Changes

Jump to: navigation, search

Declaring Visual Basic Variables and Constants

890 bytes added, 19:01, 1 August 2007
Declaring and Referencing Visual Basic Constants
companyLabel.Text = companyName
</pre>
 
== Static Variables in Visual Basic ==
 
When a variable is declared with Procedure level scope it only exists while the code in the corresponding procedure is executing. Once the procedure completes, the variable and the variable assigned to it are destroyed. Under certain circumstance it may be necessary for the variable to and the current value assign to it to persist beyond the life of the procedure. Next time the procedure is called, therefore, the variable still holds the value it held on the previous invocation of the procedure. The syntax to declare a static variable is as follows:
 
'''Static''' ''variableName'' '''As''' ''dataType''
 
In the following example the value of ''intCustCount'' will increase by one each time the ''CountCustomers()'' Subroutine is called:
 
<pre>
Public Sub CountCustomers
Static intCustCount
intCustCount = intCustCount + 1
End Sub
</pre>

Navigation menu