Sams Teach Yourself Visual Basic 6 in 24 Hours

Sams Teach Yourself Visual Basic 6 in 24 Hours

By Greg Perry

Data-Testing Functions

The Is...() functions are called the data inspection functions. When you store a value in a variable declared as a Variant datatype variable, the data inspection functions can test that variable to see what kind of datatype the variable can be. The data inspection functions are especially useful for working with user entries in controls and variables. Table 14.5 describes the data inspection functions.

Data inspection functions are functions that inspect data and return information about the datatype.

Table 14.5. Data inspection functions for testing datatypes.

Function Description
IsDate() True if the argument can convert to a Date datatype.
IsEmpty() True if the argument has not been initialized with any value since the argument's declaration. IsEmpty() works with variable arguments only, not controls.
IsNull() True if the argument holds Null (such as an empty string) and works for controls as well as variables.
IsNumeric() True if the argument can convert to a Numeric datatype.

Notice that Visual Basic supports no IsString() function. If you want to test for a String value, you must use a different kind of function. If you need more specific information about a datatype, you can use the VarType() function, which returns a value that indicates the exact datatype an argument can be. If you expect the user to enter an integer, for example, you can test with VarType() to see if the argument is a valid integer. Use Table 14.6 to determine if the return type is your expected datatype.

Table 14.6. The VarType() return values.

Return Named Literal Describes
0 vbEmpty Empty and not initialized argument
1 vbNull Invalid data or a null string argument
2 vbInteger Integer argument
3 vbLong Long argument
4 vbSingle Single argument
5 vbDouble Double argument
6 vbCurrency Currency argument
7 vbDate Date argument
8 vbString String argument
9 vbObject Object argument
10 vbError Error argument
11 vbBoolean Boolean argument
12 vbVariant Variant argument
13 vbDataObject Data Access Object (DAO) argument; an advanced database value such as a field or record
14 vbDecimal Decimal argument
17 vbByte Byte argument
8192+int vbArray Array argument of the type specified by the int addition to 8192

If VarType(dataVal) returns a number greater than 8192, subtract 8192 from the return value to arrive at the datatype (such as 12 for a Variant datatype). A return value of 8194, therefore, represents an integer array.

Share ThisShare This

Informit Network