Changes

Jump to: navigation, search

Declaring Visual Basic Variables and Constants

851 bytes added, 18:30, 1 August 2007
Understanding Variable and Constant Scope
<pre>
</pre>
 
== Declaring and Referencing Visual Basic Constants ==
 
Constants, once declared and initialized cannot be changed (hence the name ''constant' and are declared using the Visual Basic ''Const'' keyword. The syntax for declaring variables is as follows:
 
'''Const''' ''constName'' '''As''' ''datatype'' = ''value''.
 
For example, to declare a String constant named ''companyName'' with a value of ''Techotopia'' the declaration would read as follows:
 
<pre>
Const companyName As String = "Techotopia"
</pre>
 
A Visual Basic constant is referenced using the name defined when the constant was declared. For example, the following Visual Basic code sets the ''Text'' roperty of a Label control to the string value contained in the ''companyName'' constant:
 
<pre>
Const companyName As String = "Techotopia"
 
companyLabel.Text = companyName
</pre>
== Declaring and Referencing Visual Basic Constants ==

Navigation menu