Multi-Line statements for If..Then

In this vastly simplified example, I ran into a problem where a simple multi-line boolean test provided to an If…Then always generated a syntax error:

Public Function testForCURLError(theErrorNumber as Int64) As Boolean
  Var wasAnError As Boolean = FALSE
  
  If (theErrorNumber = 108 or 
    theErrorNumber = 107) Then
    
    wasAnError = true
    
  End If
  
  return wasAnError
  
End Function

Of course, once I combined the two tests separated by the “or” onto ONE line, it compiles fine.

But I don’t just have two tests. I have a half dozen. And they aren’t as simple as comparing against an integer literal.

Is there some magic Xojo syntax I’m missing here?

1 Like

You forgot the underscore after or:

Public Function testForCURLError(theErrorNumber As Int64) As Boolean
  Var wasAnError As Boolean = False
  
  If (theErrorNumber = 108 Or _ 
    theErrorNumber = 107) Then
    
    wasAnError = True
    
  End If
  
  Return wasAnError
  
End Function
2 Likes

Wow. Would have liked to see that in the syntax examples for If…Then…Else. I also searched for “Line continuation” and didn’t find anything.

That’s a very unexpected kind of syntax requirement in 2022.

Thanks!

1 Like

It’s available in more than If…Then… Else statements.

Line Continuation

Fair enough. However, the If…Then…Else documentation doesn’t explicitly say you can’t continue the statement onto a second (or nth) line. Nowadays, that’s unusual syntax for a modern language. A simple NOTE might have saved me a couple hours.

Additionally, I think the Xojo compiler’s syntax parser could give more meaningful error messages. While it’s always “user error”, I chased my tail for hours on a vanilla syntax error due to an errant semicolon at the end of a line from C++ code I had pasted in.

1 Like