Changes

Jump to: navigation, search

Declaring Visual Basic Variables and Constants

914 bytes added, 18:26, 1 August 2007
no edit summary
intNewRate = intInterestRate + 20
</pre>
 
== Understanding Variable and Constant Scope ==
 
A variables and constants can be declared anywhere in a Visual Basic project. It is important to understand, therefore, that where and how the variable is declared dictates the ''scope'' of that variable. The ''scope'' of a variable relates to where else in the application source code the variable is accessible.
 
There are four levels of scope in a Visual Basic application:
 
* Block Level Scope
 
When a variable is declared in a distinct code structure (such as an ''If'' statement or ''Do loop''), the variable is only visible and accessible to the code within that structure. For example, in the following code the ''intCustCount'' variable is only accessible to code within the ''If'' statement:
 
<pre>
If blnNewCustomer Then
Dim intCustCount As Integer
For intCustCount = 1 to 50
Do ReadCustRecord()
Next InCustCount
End if
</pre>
 
 
 
 
 
== Declaring and Referencing Visual Basic Constants ==

Navigation menu