Sams Teach Yourself Visual Basic 6 in 24 Hours
- Table of Contents
- Copyright
- About the Author
- Acknowledgments
- Introduction
- Who Should Read This Book
- What This Book Will Do for You
- Can This Book Really Teach Visual Basic in 24 Hours?
- What You Need
- Files on the Visual Basic Distribution CD-ROM
- Conventions Used in This Book
- Enough! Time Is Ticking!
- Part I: Introducing Visual Basic
- Hour 1. Visual Basic at Work
- Hour 2.Analyzing Visual Basic Programs
- Hour 3.Controls and Properties
- Hour 4.Examining Labels, Buttons, and Text Boxes
- Part II: Coding the Details
- Hour 5.Putting Code into Visual Basic
- Hour 6.Message and Input Boxes
- Hour 7.Making Decisions
- Hour 8.Visual Basic Looping
- Part III:Putting Code to Work
- Hour 9.Combining Code and Controls
- Hour 10.List Boxes and Data Lists
- Hour 11.Additional Controls
- Hour 12.Dialog Box Basics
- Part IV:Programming with Data
- Hour 13.Modular Programming
- Hour 14.Built-In Functions Save Time
- Hour 15.Visual Basic Database Basics
- Hour 16.Printing with Visual Basic
- Part V:Sprucing Up Programs
- Hour 17.Menus and Visual Basic
- Hour 18.The Graphic Image Controls
- Hour 19.Toolbars and More Graphics
- Hour 20.Writing Correct Applications
- Part VI:Advancing Visual Basic Applications
- Hour 21.Visual Basic and ActiveX
- Hour 22.Object Basics
- Hour 23.Distributing Your Applications
- Hour 24.Online Visual Basic
- Part VII:Appendixes
- Appendix A.Operator Precedence
- Appendix B.Answers
- Appendix C.Using the CD-ROM
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.
Data Conversion Functions | Next Section

Account Sign In
View your cart