#If vs If

  • Thread starter Thread starter Tom Collins
  • Start date Start date
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
 
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.
 
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)
 

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