Whether VB is a weakly or a semi-strongly typed language depends on
the Option
Explicit
setting.
(The statement must appear at the top of a code module.) If
Off
, VB is a weakly typed language; variables need
not be declared in advance, and all undeclared variables will be cast
as type Object
until they are initialized. If
On
(its default setting), each variable must be
declared in advance, but its data type need not be specified. If no
type is explicitly declared, variables are cast as type
Object
until their first use.
Although VB recognizes a number of “intrinsic” data types, each is really a wrapper around a data type found in the .NET Common Type System (CTS). VB recognizes the following intrinsic types:
A logical (True
or False
)
value. Corresponds to System.Boolean
.
A signed 8-bit numeric data type. Corresponds to
System.Byte
.
A 16-bit character data type (character code). Corresponds to
System.Char
.
A date or time value. Corresponds to
System.DataTime
.
A decimal or currency value. Corresponds to
System.Decimal
.
A double-precision floating point value. Corresponds to
System.Double
.
A signed 32-bit integral data type. Corresponds to
System.Int32
.
A signed 64-bit integral data type. Corresponds to
System.Int64
.
A reference to an object. Object
is
VB’s “universal”
data type and corresponds to System.Object
.
A signed 16-bit integral data type. Corresponds to
System.Int16
.
A single-precision floating point value. Corresponds to
System.Single
.
A reference type pointing to a fixed-length character string.
Corresponds to System.String
.
A number of other data types are available from the .NET CTS but are not wrapped by a corresponding VB intrinsic data type. These include:
System.SByte
A signed 8-bit integral data type.
System.UInt16
An unsigned 16-bit integral data type.
System.UInt32
An unsigned 32-bit integral data type.
System.UInt64
An unsigned 64-bit integral data type.
VB also allows you to create user-defined reference types by using
the Class...End
Class
construct
and user-defined value types by using the
Structure...End
Structure
construct.
Any of these data types can be used as a member of an array. Arrays can have a single dimension, or they can be multidimensional (up to 60 dimensions). The first element in an array is always at position 0.