Syntax question: #If bla bla bla then

  • Thread starter Thread starter moondaddy
  • Start date Start date
M

moondaddy

I'm looking at some sample code but dont know what to make of it. I see an
If block that looks like this:

#If bla bla bla then
Private function xyz() as Boolean
'bla bla bla
End Function
More stuff
#Else
Private function 123() as Boolean
'bla bla bla
End Function
More stuff
#End If

Why wouldnt you just write this:

If bla bla bla then
x=xyz
More stuff
Else
x=123
More stuff
End If
Private function xyz() as Boolean
'bla bla bla
End Function

Private function 123() as Boolean
'bla bla bla
End Function

Thanks.
 
hi moondaddy,
On the surface, the behavior of the #If...Then...#Else directives
appears the same as that of the If...Then...Else statements. However,
the #If...Then...#Else directives evaluate what is compiled by the
compiler, whereas the If...Then...Else statements evaluate conditions
at run time.

Conditional compilation is typically used to compile the same program
for different platforms. It is also used to prevent debugging code from
appearing in an executable file. Code excluded during conditional
compilation is completely omitted from the final executable file, so it
has no effect on size or performance.

Regardless of the outcome of any evaluation, all expressions are
evaluated using Option Compare Text. The Option Compare statement does
not affect expressions in #If and #ElseIf statements.

Note:
you can get more details on this by searching in the msdn
 
If you know at compile time that a certain part of your program is never
going to be used there isn't much point in including it. It will only make
the program slower and larger.

The most common use if #If...#Else is to separate debug code from release
code. You might have additional debuging code that shouldn't be included in
the release build. Instead of deleting it and retyping it every time you
need it, you can use #If...#Else to have the compiler automatically include
it in debug builds and remove it in release builds.

We use it in our application to include extensive exception handling in
release builds since we don't want our users to experience a sudden crash
when something goes wrong. In the debug builds this exception handling is
turned off because we actually want it to crash immediately if something
goes wrong, in order to find out why and where it happened.

/claes
 
moondaddy said:
I'm looking at some sample code but dont know what to make of it. I see
an If block that looks like this:

#If bla bla bla then

I suggest to read the documentation on "#If directive".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top