How to Initialize Static Variables to Nonzero ValuesLast reviewed: June 21, 1995Article ID: Q119737 |
The information in this article applies to:
SUMMARYNormally in Visual Basic, when a static variable is declared inside a Function or Sub procedure, it gets initialized to 0 (numeric data type) or an empty string, "" (string data type), by default. This article shows a way to initialize these variables to values other than the default.
MORE INFORMATIONWhen a variant variable is first declared, it is initialized with the EMPTY value by default. The idea here is to take advantage of this fact, by testing a dummy variant static variable with the IsEmpty function and initializing the other static variables to the values you want if this function returns TRUE. It is important to set the dummy variant to some value after you initialize your static variables, so that IsEmpty always returns FALSE for subsequent calls to the subroutine, and that because of this the other static variables are not reinitialized. Here is an example that shows how to initialize a static variant, integer, and string variable declared in a Sub called InitStatic:
Step-by-Step Example
|
Additional reference words: 1.00 2.00 3.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |