I do not have any handy at the moment, as I said I have been avoiding that construct for some time.
The question really is: what are the rules?
I ran some test. It looks like the tested variable has to be or evaluate to a boolean. It does not work if the variable is an integer, even if the integer contains the value 0 or 1.
That's what confused me because if you run "Dim i as integer: i=0: if i then" Visual Basic will gladly cast the integer into a boolean before doing the test and not complain. B4X does compile but complains (at run time) if the variable is not a boolean type, regardless of the value.
Example: This code:
Dim i As Int
i = 0
If i Then
Log("True")
Else
Log("False")
End If
compiles but produces this error at run time:
Waiting for debugger to connect...
Program started.
Error occurred on line: 18 (Main)
java.lang.RuntimeException: Cannot parse: 0 as boolean
at anywheresoftware.b4a.BA.parseBoolean(BA.java:341)
at anywheresoftware.b4a.BA.ObjectToBoolean(BA.java:410)
at b4j.example.main._appstart(main.java:94)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
at b4j.example.main.start(main.java:38)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)
where Visual Basic with similar code will run with mostly the expected result.
Sometimes the similarity between Visual Basic and B4X, while generally helpful, can be confusing.