All local variables are automatically initialised to a Default Value when they are declared.
Explicitly initialising all your local variables makes your code more readable.
Declare and Initialise
Unlike a lot of other programming languages you cannot declare and initialise on the same line.
You must declare your variable on one line and then initialise the value on a new line
Dim lMyNumber As Long
lMyNumber = 500
Integer, Short, Long, Double and Currency are all initialised to zero.
Dim iInteger As Integer
'automatic initialisation will assign the value to 0
Variable Length Strings
These are initialised to a zero-length (or empty) string.
Dim sFirstName As String
'automatic initialisation will assign the value to the empty string ""
Fixed Length Strings
These are initialised with the character represented by the ASCII code 0, or Chr(0).
These default to Empty
These default to Nothing
Static variables cannot be initialised.
© 2018 Better Solutions Limited. All Rights Reserved. © 2018 Better Solutions Limited TopPrevNext