Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between #const and const?

Tags:

vba

This class, which runs just fine contains lines like #Const UseScriptingDictionaryIfAvailable = True. I normally use Const UseScriptingDictionaryIfAvailable As Boolean = True.

I've noticed you can't explicitly declare the type with #const. Whereas As Boolean is optional in the later, its forbidden in the former. Is that the only difference? Is there an internal difference?

like image 884
Justin Dearing Avatar asked Mar 22 '26 06:03

Justin Dearing


1 Answers

That # 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/ link provides a good description of conditional compilation.

http://www.utteraccess.com/wiki/index.php/Conditional_Compilation also provides some good inputs.

like image 171
zedfoxus Avatar answered Mar 24 '26 19:03

zedfoxus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!