This section describes why variables need to be inspected when receiving it in a procedure and how to inspect a variable to determine its data type.
If are writing a procedure, and receiving a variable from the calling code through an argument,
you can not always assume that value of the variable is of certain subtype.
If you code your procedure with some assumptions, your code will crash if the calling code
fails to meet those assumptions.
To better protect your code, you want to inspect the value first, and write your code
based on the result of the inspection. Variable inspection can be performed at 3 different levels:
1. Determine the structure type of the variable. Is it an object, array, or scalar.
2. Determine the data subtype of the variable. If it is an object, check its properties;
If it is an array, check its elements; If it is a scalar, check the subtype of the value:
Byte, Integer, Long, Single, Double, Date, Currency, Boolean, or String.
3. Determine the status of the data. Is it Empty or Null.
VBScript offers a number of built-in functions to help you to inspect a variable:
IsObject(variable) - Returns True if the specified variable is an object
IsArray(variable) - Returns True if the specified variable is an array
IsDate(variable) - Returns True if the specified variable can be converted to a date
IsEmpty(variable) - Returns True if the specified variable is Empty
IsNull(variable) - Returns True is the specified variable is Null
IsNumeric(variable) - Returns True if the specified variable can be converted to a number
TypeName(variable) - Returns the type name of the specified variable
SubType(variable) - Returns the subtype code of the specified variable