Variable Initialization Values
- Last UpdatedJul 18, 2023
- 1 minute read
VBA variables are initialized when first declared. Numeric variables are initialized to 0 (zero). Variable-length strings are initialized to zero-length strings (""). Fixed length strings are filled with zeros. Variant variables are initialized to Empty.
To be sure of the contents of a variable, a valid value needs to be assigned to it before it is used as an operand in a VBA statement. For details, see Assignment Operator.
Note: Only implicitly declared variables can be assigned an initial value in the declaration. However, as explicit declaration is preferred practice in VBA, explicit variables need to be declared before they can be assigned a value.
Every call to a procedure will reinitialize the value of all objects (except static variables) declared within that procedure.
Note: In VBA, use a static variable, a modular variable, or a Plant SCADA tag to store variable values between procedures. For details, see Scope of VBA.
Objects (including variables) declared in VBA are only initialized when referenced by a running piece of code, and are removed from memory when all references are closed.
In the Plant SCADA multithreaded environment, VBA remains active in memory only so long as a procedure is being processed. At the completion of a VBA procedure, all objects no longer referenced by that procedure are removed from memory. For details, see Multithread Considerations with VBA.