Understanding Visual Basic Variable and Constant Types

From Techotopia
Revision as of 18:56, 10 July 2007 by Neil (Talk | contribs) (Char Variable Type)

Jump to: navigation, search

A variable is a location in memory where a value can be stored during the execution of a Visual Basic application. Visual Basic variables are assigned names by the programmer when they are declared so that they can easily be referenced in other places in the application code.

These values may either be declared as variable (in that once the value has been assigned it can be changed later in the Visual Basic code) or as constant (in that once the value has been assigned it cannot be changed elsewhere in the code).

In the next chapter (Declaring Visual Basic Variables) we will look at how to create Visual basic variables and assign values to them. Before doing that, however, we need to look at the various types of variables that are available.


Contents


Boolean Variable

The Visual Basic Boolean variable type holds a value of true or false. Internally these are actually stored as the numbers 1 and 0 representing true and false respectively. Boolean values are used in conditional statements to decide whether particular parts of Visual Basic code should be executed or not (see Visual Basic Flow Control for more details) on conditional statements.

Char Variable

The Char variable type holds a single character (such as the letter 'B'). The value of a Char can be any character. Internally, a number in the range 0 to 65,553 is used to represents the character value as defined by the ASCII table. As an example when the letter 'Z' is assigned to a Visual Basic Char variable, the number 90 is actually stored in the variable location.


Byte Variable Type

A Byte variable holds a positive number in the range 0 to 255. because of the limited range, Byte variables should be used with caution. An attempt to assign a negative value, or a value greater than 255 to a Visual Basic Byte variable will result in an error.

Date Variable