Besides setting the types of variables and the functions for converting between types, Visual Basic provides two functions that let you examine the-type of a variable. They are the VarType() and TypeName() functions. Both functions accept as argument the name of a variable, and they return a number (the VarType() function) or a string (the TypeName() function) indicating the type of the variable. The VarType() function returns one of the numbers shown in Table 3.4, depending on the type of its argument.
It a Number or a String?
Another set of Visual Basic functions returns variables’ data types, but not the exact type:
- IsNumeric() Returns True if its argument is a number (Integer, Long, Currency, Single, or Double). Use this function to determine whether a variable holds a numeric value before passing it to a procedure that expects a numeric value or process it as a number.
- IsDate() Returns True if its argument is a valid date (or time).
- IsArray() Returns True if its argument is an array.
- IsNull(), IsEmpty() Detects whether a variable hjas been initialized or is a Null/Empty value.
- IsMissing() Returns True if a certain optional procedure argument is missing (you’ll see how the IsMissing() function is used later in this chapter).
- IsObject() Returns True if its argument is an object.
All these functions are described in Appendix A on the CD.