Wednesday, October 27, 2010

Variables

A variable is a value that can change. For instance, weather forecasters often refer to variable winds and variable temperatures - meaning that the wind and temperature could change without warning. In the context of computers, however, variables only change when told to and cannot do anything on their own.

Variables must be declared before they are used in Visual Basic.NET. To declare a new variable, you must use the Dim keyword, which is short for "dimension", referring to the process of reserving memory for the new variable.

You can create any variable you need using Dim. When you hear the word "variable', just remember that it is just a pointer to a location in memory in which some data is stored.

Variables may be used in many different situations such as storing a username, storing numbers for calculation, storing a weather temperature etc.

A declaration statement is used to declare the existence of the variable. It is defined as a particular data type. It may then be assigned a value.

Syntax
Dim VariableName As DataType

Code eg: Declaring a variable.
In this case, the variable is a String data type called strUserFirstName with a value of Straximo 
 
Dim strUserFirstName As String = "Straximo"

No comments:

Post a Comment