Syntax |
CBool(expression) |
Description |
Converts expression to True or False, returning a Boolean value. |
Comments |
The expression parameter is any expression that can be converted to a Boolean. A runtime error is generated if expression is Null. All numeric data types are convertible to Boolean. If expression is zero, then the CBool returns False; otherwise, CBool returns True. Empty is treated as False. If expression is a String, then CBool first attempts to convert it to a number, then converts the number to a Boolean. A runtime error is generated if expression cannot be converted to a number. A runtime error is generated if expression cannot be converted to a Boolean. |
Example |
This example uses CBool to determine whether a string is numeric or just plain text. Sub Main() Dim IsNumericOrDate As Boolean s$ = 34224.54 IsNumeric = CBool(IsNumeric(s$)) If IsNumeric = True Then MsgBox s$ & " is either a valid number!" Else MsgBox s$ & " is not a valid number!" End If End Sub |
See Also |
CCur (function); CDate, CVDate (functions); CDbl (function); CInt (function); CLng (function); CSng (function); CStr (function); CVar (function); CVErr (function); Boolean (data type). |
C |