#If vs If

T

Tom Collins

Can someone explain what the difference of these statements are to me? When
I run the Test procedure, I only get one message box with "AAA".

Public Const DEBUG_DEFINED As Boolean = True

Sub Test()
If DEBUG_DEFINED Then
MsgBox "AAA"
End If


#If DEBUG_DEFINED Then
MsgBox "BBB"
#End If
End Sub


Thanks

Tom
 
D

Dirk Goldgar

Tom Collins said:
Can someone explain what the difference of these statements are to
me? When I run the Test procedure, I only get one message box with
"AAA".

Public Const DEBUG_DEFINED As Boolean = True

Sub Test()
If DEBUG_DEFINED Then
MsgBox "AAA"
End If


#If DEBUG_DEFINED Then
MsgBox "BBB"
#End If
End Sub


Thanks

Tom

The #If ... #End If statements are conditional compilation directives.
Only literals, operators, and conditional-compiler constants (declared
with the #Const directive) are valid in the condition expression of an
#If directive. In your code above, DEBUG_DEFINED is not a
conditional-compiler constant, so the #If ... #End If directive is
invalid.

If you write ...

#Const DEBUG_DEFINED = True

Sub Test()

#If DEBUG_DEFINED Then
MsgBox "BBB"
#End If

End Sub

.... then you'll get the "BBB" message.
 
T

Tom Collins

That makes sense. Thanks.


Dirk Goldgar said:
The #If ... #End If statements are conditional compilation directives.
Only literals, operators, and conditional-compiler constants (declared
with the #Const directive) are valid in the condition expression of an
#If directive. In your code above, DEBUG_DEFINED is not a
conditional-compiler constant, so the #If ... #End If directive is
invalid.

If you write ...

#Const DEBUG_DEFINED = True

Sub Test()

#If DEBUG_DEFINED Then
MsgBox "BBB"
#End If

End Sub

... then you'll get the "BBB" message.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Top