Article ID: 119737 - View products that this article applies to.
This article was previously published under Q119737
Normally 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.
When 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:
Article ID: 119737 - Last Review: December 9, 2003 - Revision: 2.0
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.