Visual Basic Data Types
Visual Basic has many different data types. We are interested in only a few
for now.
- String variables are a
nonnumeric data type that can be used to store text values up to 2 billion
characters long. The maximum length will differ on individual machines
because of available memory, overhead, and other programs.
Any character may be stored in a string variable.
- Short (int16) variables
can be used to store a whole number between -32,786 and 32,767
- Integer (int32) varibles
can be used to store a whole number between -2,147,483,648 and 2,147,483,647
- Long (int64) variables use
8 bytes and can store very large whole numbers.
Note: If you know that a variable will always
store whole numbers (such as 12) rather than numbers with a fractional amount
(such as 3.57), declare it as an Integer data type. Operations are faster with
integers, and these types consume less memory than other data types.
- Single variables are used to store
single-precision floating-point numbers. They can store numbers with
fractional values.
- Double variables are used to
double-precision floating-point numbers. They can store numbers that are very
large, very small, or have many decimal positions.
- Decimal variables are also used to store
numbers with fractional values. Because the value is stored differently in
Decimal variables they are not as subject to rounding errors as Single an
Double.
The highest positive values of the non-integral types are
7.9228162514264337593543950335E+28 for Decimal,
3.4028235E+38 for Single, and
1.79769313486231570E+308 for Double.
- Boolean variables are used as a flag or
switch. The value of a Boolean variable is either True or False. Boolean
variables are used to indicate the absence or presence of a certain
condition. The properties AutoSize, Visible, and Enabled, MultiLine are all
Boolean properties.