Programming Functions
Type conversion, conditional logic, and general-purpose utilities.
CDbl
CDbl(Value)
Converts Value to a Double (64-bit floating-point number).
Returns: Double
Examples:
CDbl("3.14") ' 3.14
CDbl(42) ' 42.0
CDbl(Price)
CInt
CInt(Value)
Converts Value to an Integer (32-bit). Decimal portions are rounded (banker's rounding at midpoints).
Returns: Integer
Examples:
CInt("42") ' 42
CInt(3.7) ' 4
CInt(3.5) ' 4
CInt(Quantity)
CStr
CStr(Value)
Converts Value to a String.
Returns: String
Examples:
CStr(42) ' "42"
CStr(3.14) ' "3.14"
CStr(True) ' "True"
CStr(OrderDate)
IIF
IIF(Value, IfTrue, IfFalse)
Evaluates Value as a condition and returns IfTrue if the condition is true, or IfFalse otherwise. All three arguments are always evaluated.
| Parameter | Description |
|---|---|
Value |
Boolean condition |
IfTrue |
Value to return when condition is True |
IfFalse |
Value to return when condition is False |
Returns: Object
Examples:
IIF(Score >= 50, "Pass", "Fail")
IIF(IsNull(Name), "Unknown", Name)
IIF(Qty > 0, Price * Qty, 0)
Tip: For multi-line conditional logic use an
If / Else / End Ifblock instead.
IsNull
IsNull(Value, [ValueIfNull])
Tests whether Value is null (DBNull) or Nothing.
With one argument, returns True if Value is null/nothing, False otherwise.
With two arguments, returns Value if it is not null, or ValueIfNull as a replacement when it is.
| Parameter | Description |
|---|---|
Value |
The value to test |
ValueIfNull |
(optional) Replacement value when Value is null |
Returns: Boolean (one argument) or Object (two arguments)
Examples:
IsNull(Name) ' True if Name is null
IsNull(Price, 0) ' returns Price, or 0 if Price is null
IsNull(Description, "N/A") ' returns Description or "N/A"
IsNumeric
IsNumeric(Value)
Returns True if Value can be interpreted as a number.
Returns: Boolean
Examples:
IsNumeric("42") ' True
IsNumeric("3.14") ' True
IsNumeric("hello") ' False
IsNumeric(Price)
Random
Random(MinValue, MaxValue)
Returns a random Double in the range [MinValue, MaxValue).
| Parameter | Description |
|---|---|
MinValue |
Lower bound (inclusive) |
MaxValue |
Upper bound (exclusive) |
Returns: Double
Examples:
Random(0, 1) ' random between 0.0 and 1.0
Random(1, 101) ' random between 1.0 and 101.0
CInt(Random(1, 7)) ' random integer 1–6 (die roll)