Excel - Declaration w initialization - for dummies

Asked By Mac on 11-Dec-09 05:59 AM
Hello,

how do I declare and initialize at the same time? If  I cannot use 'Dim
boolVar as boolean = false' - what is correct, then?




Per Jessen replied to Mac on 11-Dec-09 06:05 AM
Hi

When you declare a boolean variable, it is False by default. Just use:

Sub Test
Dim boolVar as Boolean
Debug.Print boolVar' See the value of the variable in the immediate window
End Sub

Regards,
Per
Jacob Skaria replied to Mac on 11-Dec-09 06:32 AM
Hi Mac

--Unlike many other languages, VBA or even VB does not allow you to
initialize variables; this must be done with a separate executable statement.

--Each variable does have a default initialization value. Numeric variable
types are initialized to zero, Strings are initialized to "" or vbNullString,
Booleans are initialized to False and so on...

--VB .NET allows you to initialize variables in the declaration.
Dim x As Single = 1.23
Dim txt As String = "This is a test"


--
Jacob
Mac replied to Jacob Skaria on 11-Dec-09 06:41 AM
I thought as much, glad to have it confirmed. Thank you!