What is the difference between #const and const?

This class, which works just fine, contains strings like #Const UseScriptingDictionaryIfAvailable = True

. I usually use Const UseScriptingDictionaryIfAvailable As Boolean = True

.

I noticed that you cannot explicitly declare a C # type const. While As Boolean

optional hereinafter, it is prohibited in the first. Is this the only difference? Is there an internal difference?

+3


source to share


2 answers


This is # for conditional compilation. If you want to conditionally compile a certain piece of code, you can use #. For example:

#Const MyEnv = "Testing"

Sub TestMacro()

 #If MyEnv = "Testing" Then
   ' do something here
   Debug.Print "Logging for testing"
   Dim X as String
   X = "..."
 #Else
   Dim Y as Int
   Y = 100
 #End If

End Sub

      



https://usefulgyaan.wordpress.com/2013/06/26/vba-trick-of-the-week-conditional-compiling/ the link gives a good description of conditional compilation.

http://www.utteraccess.com/wiki/index.php/Conditional_Compilation has some good inputs too.

+4


source


Const

is your usual "normal" constant declaration.

#Const

different, it allows you to define constants specifically for use with type compiler directives #If

.

The "regular" constant will not be available to the compiler for conditional compilation:



Const DEBUG As Boolean = True

      

However, this:

#Const DEBUG = True

      

0


source







All Articles