[Gambas-user] Syntax help for IF after a Try statement

Adam Ant adamnt42 at ...626...
Thu Aug 9 04:55:04 CEST 2012


On Thu, Aug 9, 2012 at 11:23 AM, rocko <sunblaster5 at ...626...> wrote:
> Trying to get a message.info to display when a successful connection
> to a database is made.
> Tried using an 'Else If' after a 'Try $hConn.Open' statement
> but that gives an error.
> So tried a simple 'If' but I'm not sure how the syntax should be.
>
> CODE:
>  Try $hConn.Open
>   If Error Then Print "Database cannot be opened. Error = ", Error.Text
>
>   If $hConn.Open Then
>       Message.Info("You are now connected to the database.")
>       Endif
>

OK Rokko,

>From the IF help page...

If <expression> Then
 ...
else
...
End If

<expression> must be some "construct" that RETURNS a value that can be
interpreted as being True or False. Where "construct" is a boolean
value(1) or a function that returns a boolean(2) or a statement that
evaluates as a boolean(3) and some others.
1) Dim myValue as Boolean=True
2) Function MyValue() as Boolean
3) ThisString=ThatString


Connection.Open from the help page at
http://gambasdoc.org/help/comp/gb.db/connection/open?v3 is a SUB.  It
doesn't return anything.  Do you now see what's wrong with your code?

See also http://gambasdoc.org/help/cat/methoddecl?v3

The gambas help pages explain everything, but they are very very
succinct.  Above my desk is a large sign that says "READ EVERY WORD OF
THE GAMBAS HELP PAGE!", to which I have to constantly refer.


hth
Bruce




More information about the User mailing list