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

Numeric Variables

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).

Variant Variables

These default to Empty

Object Variables

These default to Nothing


Static variables cannot be initialised.

© 2020 Better Solutions Limited. All Rights Reserved. © 2020 Better Solutions Limited TopPrevNext