Android Question Compiler Conditional Symbols

bocker77

Active Member
Licensed User
Longtime User
This is probably a B4X 101 question but I can't see anywhere in the forum that answers this question.

In Project=>Build Configuration I add an entry in Conditional Symbols. It looks as if the symbol defaults to True. My question is how do I go about manipulating the symbol to True or False? Or maybe I am not understanding how this all works.

I want to use symbols for testing so when I want to test a portion of my code I don't have to keep massaging the code to do this.
 

LucaMs

Expert
Licensed User
Longtime User
(The image is from B4J but it's the same thing).

1736639385383.png


You can create your own configurations, each containing one or more conditional symbols (words), separated by commas.

You can also add symbols to the default configuration named... "Default".
For example, I could add to "Default": ForMeOnly.

At runtime, I would have the symbols of the configuration I selected; in the example, "Default", I have not created a new configuration, and I could write:
B4X:
#IF ForMeOnly
'''
#ELSE
'''
#END IF
The "Default" configuration already contains "DEBUG" and "RELEASE" although they are not visible, so I could use combinations of the 3 words contained in the configuration named "Default".

It is not "True" or "False", it is: #IF (the selected configuration contains) [one of the symbols]
 
Last edited:
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
Thanks for the reply.

What is confusing me is that I saw the use of Not(symbol) in the forum which made me think of them as boolean.

With this code below I believe all three code blocks would be entered.

B4X:
#If Debug
      #If tst1
            do something...
      #End
      #If tst2
            do something...
      #End
      #If tst3
            do something...
      #End
#End

Or with the below code, I believe only the first code block will be used.

B4X:
#If Debug
      #If tst1
            do something...
      #Else If tst2
            do something...
      #Else If tst3
            do something...
      #End
#End

I guess I could use the Not() though.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
With this code below I believe all three code blocks would be entered.
B4X:
#If Debug
      #If tst1
            do something...
      #End
      #If tst2
            do something...
      #End
      #If tst3
            do something...
      #End
#End
Keeping the "Default" configuration selected, launching the project in Debug mode, all three TESTS would be executed; the code inside them would be executed (compiled) only if those "symbols" have been added to the "Default" configuration.

Or with the below code, I believe only the first code block will be used.
B4X:
#If Debug
      #If tst1
            do something...
      #Else If tst2
            do something...
      #Else If tst3
            do something...
      #End
#End
If you added tst1 to your configuration, the code after that line will be executed (compiled) and the other two tests will be ignored. If you did NOT add tst1 but added tst2, the code after that line will be executed (compiled) and tst3 will be ignored.

I guess I could use the Not() though.
Yes, you can write:
#IF NOT(DEBUG)
or
#IF NOT(tst1)

Note that the editor immediately highlights which part of the code will be compiled, based on the symbols of the currently selected configuration.
 
Last edited:
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
Thanks again for your help.

Now I am no longer in the dark as to how all of this works. Instead of manipulating boolean switches, as I imagined, you use the Conditional Symbol by adding and removing entries, as in my case to test portions of my code. Brilliant!
 
Upvote 0
Top