9.3. Using Functions to Convert Data from One Type to Another

VBA provides a full set of functions for converting data from one data type to another. These functions fall into two distinct groups: simple data conversion and more complex data conversion.

Table 9.1 lists VBA's functions for simple data conversion.

Table 9.1. VBA's Functions for Simple Data Conversion
Function(Arguments)Data Type Returned
CBool(number)Boolean
CByte(expression)Byte
CCur(expression)Currency
CDate(expression)Date
CDbl(expression)Double
CInt(expression)Integer
CLng(expression)Long
CSng(expression)Single
CStr(expression)String
CVar(expression)Variant

For example, the following statements declare the untyped variable varMyInput and the Integer variable intMyVar and then display ...

Get Mastering VBA for Microsoft Office 2007, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.