View contents of this chapter

The Data Type Conversion Functions

The following table describes data type conversion functions, denoted by their initial letter C (for convert). Each function converts its argument from one data type to another.

Function name Description
CBool() Converts its argument to the Boolean data type
CByte() Converts its argument to the Byte data type
CCur() Converts its argument to the Currency data type
CDate() Converts its argument to the Date data type
CDbl() Converts its argument to the Double data type
CDec() Converts its argument to the Decimal data type
CInt() Converts its argument to the Integer data type
CLng() Converts its argument to the Long data type
CSng() Converts its argument to the Single data type
CStr() Converts its argument to the String data type
CVar() Converts its argument to the Variant data type

You must be able to convert the argument to the target data type. You can't convert the number 523456700 to a Byte data type with CByte(), because the Byte data type can't hold a number that large.

Play Sound If the expression passed to the function is outside the range of the data type being converted to, an error occurs.

Consider the following statements:

int1 = CInt(8.5)    ' stores an 8 in int1
int2 = CInt(8.7)    ' stores an 9 in int2
cur1 = CCur(120)  ' converts 120 to currency data type
dbl1 = CDbl(120)   ' converts 120 to double data type
sng1 = CSng(120) ' converts 120 to single data type
var1 = CVar(120)  ' converts 120 to variant data type



© Universal Teacher Publications        INDEX Previous Screen Next Screen