O'Reilly logo

Visual Basic 2012 Programmer's Reference by Rod Stephens

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

TYPE CHARACTERS

Data type characters identify a value’s data type. The following table lists the data type characters of Visual Basic.

CHARACTER DATA TYPE
% Integer
& Long
@ Decimal
! Single
# Double
$ String

You can specify a variable’s data type by adding a data type character after a variable’s name when you declare it. When you use the variable later, you can omit the data type character if you like. For example, the following code declares variable num_desserts as a Long and satisfaction_quotient as a Double. It then assigns values to these variables.

Dim num_desserts&
Dim satisfaction_quotient#
 
num_desserts = 100
satisfaction_quotient# = 1.23

If you have Option Explicit turned off, you can include a data type character the first time you use the variable to determine its data type. If you omit the character, Visual Basic picks a default data type based on the value you assign to the variable.

If the value you assign is an integral value that will fit in an Integer, Visual Basic makes the variable an Integer. If the value is too big for an Integer, Visual Basic makes the variable a Long. If the value contains a decimal point, Visual Basic makes the variable a Double.

If you set a variable equal to a True or False, Visual Basic makes it a Boolean.

In Visual Basic, you surround date values with # characters. If you assign a variable to a date value, Visual Basic gives the variable the Date data type. The following code assigns Boolean and Date variables: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required