HandsOn Asking Questions about the Variable Type

1. Open the Immediate window and type the following statements that assign values to variables:

birthdate = #1/1/1981 firstName = "John"

2. Now, ask Visual Basic what type of data each variable holds: ?varType(age)

When you press Enter, Visual Basic returns 2. The number 2 represents the Integer data type.

?varType(birthdate)

Now Visual Basic returns 7 for Date. If you make a mistake in the variable name (let's say you type birthday instead of birthdate), Visual Basic returns zero (0).

?varType(firstName)

From this statement Visual Basic tells you that the value stored in the firstName variable is a string (8).

Part I

Table 3-3: Values returned by the VarType function

Constant

Value

Description

vbEmpty

0

Empty (uninitialized)

vbNull

1

Null (no valid data)

vblnteger

2

Integer

vbLong

3

Long integer

vbSingle

4

Single-precision floating-point number

vbDouble

5

Double-precision floating-point number

vbCurrency

6

Currency value

vbDate

7

Date value

vbString

8

String

vbObject

9

Object

vbError

10

Error value

vbBoolean

11

Boolean value

vbVariant

12

Variant (used only with arrays of variants)

vbDataObject

13

Data access object

vbDecimal

14

Decimal value

vbByte

17

Byte value

vbUserDefinedType

36

Variants that contain user-defined types

vbArray

8192

Array

0 0

Post a comment