O'Reilly logo

VBScript in a Nutshell, 2nd Edition by Ron Petrusha, Matt Childs, Paul Lomax

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

Name

VarType Function

Syntax

VarType(varname)
varname

Use: Required

The name of a variable.

Return Value

An Integer representing the data type of varname.

Description

Determines the data type of a specified variable.

Rules at a Glance

  • The following intrinsic constants can test the return value of the VarType function:

Constant

Value

Data type

vbBoolean

11

Boolean

vbByte

17

Byte

vbCurrency

6

Currency

vbDataObject

13

A data access object variable

vbDate

7

Date

vbDecimal

14

Decimal

vbDouble

5

Double-precision floating-point number

vbEmpty

0

Uninitialized

vbError

10

An error type that indicates a missing argument

vbInteger

2

Integer

vbLong

3

Long integer

vbNull

1

No valid data

vbObject

9

A generic object

vbSingle

4

Single-precision floating-point number

vbString

8

String

vbVariant

12

Variant—returned only with vbArray (8194)

  • If varname is an array created by VBScript code, the VarType function returns 8200 (vbArray) and vbVariant.

  • If varname is an array returned to the script by a component, the VarType function returns 8200 (vbArray) and the value representing the data type of the array. For instance, a Visual Basic Integer array returned to a VBScript script produces a value of 8196(vbInteger + vbArray).

  • To test for an array, you can use the intrinsic constant vbArray. For example:

    If VarType(myVar) And vbArray Then
         MsgBox "This is an array"
    End If

    Alternatively, you can also use the IsArray function.

Programming Tips and Gotchas

  • When you use VarType with an object variable, you may get what appears to be an incorrect ...

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