Wish [B4X] In-line compiler directive

JesseW

Active Member
Licensed User
Longtime User
I was just thinking it'd be nice to be able to do this
B4X:
Dim a As String = Iif(#If_B4a, "Google Maps", "Maps")

just wishful thinking. I'm grateful we can do that using the old school, long hand method, although it takes many more lines of code.

Thank you Erel and community for a truly great development environment!

ps. HEY!!! I just thought of this!!!
B4X:
    Public isB4A as Boolean = False
    Public isB4i as Boolean = False
    Public isB4J as Boolean = False
#If B4A
    isB4A = True
#Else If B4I
    isB4i = True
#Else If B4J
    isB4J = True
#End If
...
Dim a As String = Iif(isB4A, "Google Maps", "Maps")

Haha! I'm going to start including that in every projects MainPage Global Variables! Maybe this should be titled as a tutorial? ?
 

AnandGupta

Expert
Licensed User
Longtime User
I was just thinking it'd be nice to be able to do this
B4X:
Dim a As String = Iif(#If_B4a, "Google Maps", "Maps")

just wishful thinking. I'm grateful we can do that using the old school, long hand method, although it takes many more lines of code.

Thank you Erel and community for a truly great development environment!

ps. HEY!!! I just thought of this!!!
B4X:
    Public isB4A as Boolean = False
    Public isB4i as Boolean = False
    Public isB4J as Boolean = False
#If B4A
    isB4A = True
#Else If B4I
    isB4i = True
#Else If B4J
    isB4J = True
#End If
...
Dim a As String = Iif(isB4A, "Google Maps", "Maps")

Haha! I'm going to start including that in every projects MainPage Global Variables! Maybe this should be titled as a tutorial? ?
There is a bit difference in using the #if B4? (compiler directive) and isB4? or XUI.IsB4A (variable)

In compiler directive you can have codes specific to both B4J and B4A (say) in same .bas file and no error will show in log, as B4J will see only its codes and vice versa.
But in variable logic, the values must satisfy the ide for both, else you get errors.
 

JesseW

Active Member
Licensed User
Longtime User
B4X:
Dim a As String = IIf(XUI.IsB4A, "Google Maps", "Maps")
Thank you Erel. I should not have doubted. I am weak ?

In compiler directive you can have codes specific to both B4J and B4A (say) in same .bas file and no error will show in log, as B4J will see only its codes and vice versa.
But in variable logic, the values must satisfy the ide for both, else you get errors.
yes, I know, but in my example, i was only choosing between two strings. and there's no b4j component in the project i'm currently working on. Thanks for your input
 
Top