Reputation: 4966
I have a constant which is set to True or False. How can I use a conditional operator on the constant?
For e.g. I want to do someting like this:
Public Const IsMale = true
If IsMale = True Then
...
Else
...
End If
But I get following compile error:
Compile Error: Invalid Outside Procedure
Upvotes: 0
Views: 100
Reputation: 12353
Declare the const IsMale
at module level and don't assign value to it later(Not permitted although).
Below is sample code
Public Const IsMale = True
Sub test()
If IsMale Then
MsgBox "Male"
Else
MsgBox "FeMale"
End If
End Sub
Or
If you want to define locally use below(remove public keyword)
Sub test()
Const IsMale = True
If IsMale Then
MsgBox "Male"
Else
MsgBox "FeMale"
End If
End Sub
Read more below
Upvotes: 3