Type conversion functions
Each function coerces or forces an expression to a specific data type. The expression will be converted to a specific data type. For example, CBool(expression). This function converted expression to a Boolean data type which is TRUE or FALSE with condition expression is a numeric or valid string, otherwise Rune-time error '13': Type mismatch. The function name determines the return type as shown in the following:
Function | Returns the expression converted to a |
CBool | Boolean data type (Boolean). |
CByte | Byte data type (Byte). |
CCur | Currency data type (Currency). |
CDate | Date data type (Date). |
CDbl | Double data type (Double). |
CDec | Decimal data type (Decimal). |
CInt | Integer data type (Integer). |
CLng | Long data type (Long). |
CLngLng | LongLong data type (LongLong). |
CLngPtr | LongPtr data type (LongPtr). |
CSng | Single data type (Single). |
CStr | String data type (String). |
CVar | Variant data type (Variant). |
VBA Vode:
Sub ExampleTypeOfConverstion()
Debug.Print CBool(1) 'Return True
Debug.Print CBool(0) 'Return False
Debug.Print CBool(-1) 'Return True
Debug.Print CBool(100) 'Return True
' Debug.Print CBool("TEST") 'Rune-time error '13': Type mismatch
End Sub
excel training online, visual basic for applications at below links.
Microsoft Reference-Type-conversion-functions
Other Reference-Data-types-category
Leave your comments if you have any request.
Practice makes perfect.
Thank You.