CLng, CDbl, CInt, CBool, CDate, CStr
All these functions work in a similar way they all convert a specified expression to the respective type.
Use -
VB Code:
Clng([Expression]) as long CDbl([Expression]) as Double CInt([Expression]) as Integer CBool([Expression]) as Boolean CDate([Expression]) as Date CStr([Expression]) as String
[Expression] being the thing we wish to convert, the functions explain themselves but i'll just go through what each does,
CLng - Converts a specified expression so it will fit into a long variable type
CDbl - Converts a specified expression so it will fit into a Double variable type
CInt - Converts a specified expression so it will fit into a Integer variable type
CBool - Converts a specified expression so it will fit into a Boolean variable type
CDate - Converts a specified expression so it will fit into a date variable type
CStr - Converts a specified expression so it will fit into a string variable type
Example
To use these functions is very simple, (myLong, myString etc are defined varibles as there name suggest so myString will be a string etc)
VB Code:
myLong = CLng(Text1.text) 'Text1 must contain digits myDouble = CDbl(Text1.text) 'Text1 must contain digits myInteger = CInt(Text1.text) 'Text1 must contain digits (Whole numbers no decimals) myBoolean = CBool(Text1.text) 'Text1.text must contain True Or False or 0 or 1 myDate = CDate(text1.text) 'Text1 must contain a valid date ie (26/10/1926) myString = CStr(Text1.text) 'You wouldnt need to do this since text1.text is allready a string :)
Note - trying to convert impossible expressions will result in a Type Mismatch Error ie
VB Code:
myBoolean = CBool("Ya Its Not Gonna Work")




Reply With Quote