|
|
 |
|
|
|
|
Visual Basic 2008 9.0 .NET Examples and Ebook
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
What are Variables
| This example will also bring the text "Hello World" to the console, but this time we will use variables.
Variables are dataholders which can be used at runtime to save information. The content of the variable can change/vary at runtime. |
| Module Example
Sub Main()
Dim message As String
message = "Hello World !"
Console.WriteLine(message)
Console.ReadLine()
End Sub
End Module Download Broncode |
Up
Declaration of a Variable
| Before our algorithm can use a variable, we will declare this variable to the compiler.
When declaring the variable we'll defined : - the identifier of the variable - the datatype of the variable, by using a "type specifier" in the form of an As-clause, keyword As followed by the name of the datatype
Keyword Dim is needed to mark this line as a declaration. |
Up
Datatypes
| Two often used datatypes are : - String : used for alphanumeric data ( text ) - Integer : used for numeric data ( integral values )
The datatype specifies what information the variable can contain, and what actions we can perform on or with that variable. For instance, two numeric variables can contain numeric values which can be added, multiplied, divided, ... . |
Up
Assignment
| To set a variable to a specific value, the value has to be assigned to this variable. An assignation often looks like this : left-part = right-part
= is the assignation operator.
The value expressed by the right-part is assigned to the left-part.
The value ( to assign ) can be expressed is all kinds of forms. In the above example a String literal is used. But this could also be expressed by referring to another String variable.
It is also possible to initialize the variable in the declaration line. Just put an assignation-clause ( = followed by the expression expressing the value to assign ) after the type specifier.
Between the parentheses of Console.WriteLine we place an expression that will evaluated to the value we want to output to the console. |
This version ( published on 2008-06-24 ) is printed from http://www.studyvb.com, visit the website for more recent information.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|