Conditional Compilation

Is it possible to have your own conditional compilation variable like “Dosometimes”, that you can set True or False; and have code either compile or not?

If so how?

Define it as a constant

#If Dosometimes 'your code #endIf

Edit (Paul): Added Code tags.


Waw, ‘Learning all the time’ would the late Benny Hill have said. Thought only predefined ones like #DebugBuild could be used. Very useful!

#if can use any “constant boolean expression”…?Endif

what this means is a constant or literal can be used - but it can be any type as long as its a constant or literal

#if “this” = “this” // <<<< evaluates to true so the code would be compiled

#if 1 = “this” // <<< gives a type mismatch since one is an integer & the other a string
msgbox 1 = this"

#if kThisStringConstant = “this” // if the constants i defined as a string and contains “this” the code will execute
msgbox “this = this”

I would like to make something like this: (conditional compilation)

dim x as integer = App.StageCode dim b as Boolean = (x < 3) #If b = true // run some code if not finale release break #endif

Since b is not a constant it’s not going to work this way. What would be the simplest solution to achieve this ?

What about

[code] dim x as integer = App.StageCode

If x < 3 then
const b = True
#If b then
// run some code if not finale release
end if

It means a bit more code , but in the end, what is in the #If b then/#EndIf block is conditional compilation.

Yes, you’ve got 'm Michel. Forgot to use a constant this way.
In my current project I am building the Unittesting into the application itself, so it would be nice automatically not to compile it in when releasing.

Don’t forget that you can set the values of constants in build scripts too. For instance, if you had a build script ask a question (like Beta or Release?), you could set a constant to reflect that:

ConstantValue("isBetaBuild") = "true"