Examining Variable Types VB Help

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.

TABLE 3. 4

TABLE 3. 4

TABLE 3.4

TABLE 3.4

It a Number or a String?

Another set of Visual Basic functions returns variables’ data types, but not the exact type:

  1. 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.
  2. IsDate() Returns True if its argument is a valid date (or time).
  3. IsArray() Returns True if its argument is an array.
  4. IsNull(), IsEmpty() Detects whether a variable hjas been initialized or is a Null/Empty value.
  5. IsMissing() Returns True if a certain optional procedure argument is missing (you’ll see how the IsMissing() function is used later in this chapter).
  6. IsObject() Returns True if its argument is an object.

All these functions are described in Appendix A on the CD.

Posted on November 4, 2015 in Visual Basic: The Language

Share the Story

Back to Top
Share This