Math, Selection & Format Commands (V26/V27)

MIN / MAX

Syntax: MIN(a, b) | MAX(a, b)

Return the smaller or larger of two numeric values.

LOCAL x AS LONG
x = MIN(10, 20)    ' x = 10
x = MAX(10, 20)    ' x = 20

IIF

Syntax: IIF(condition, trueExpr, falseExpr)

Inline conditional: returns trueExpr if condition is true, otherwise falseExpr.

x = IIF(a > b, a, b)     ' Like MAX(a,b)
PRINT IIF(x = 0, "zero", "non-zero")

CHOOSE

Syntax: CHOOSE(index, value1, value2, ...)

Returns the value at the given 1-based index.

s = CHOOSE(2, "red", "green", "blue")   ' s = "green"
n = CHOOSE(month, 31, 28, 31, 30, 31)   ' days in month

SWITCH

Syntax: SWITCH(cond1, value1, cond2, value2, ...)

Evaluates conditions left-to-right, returns the value of the first true condition.

grade = SWITCH(score >= 90, "A", score >= 80, "B", score >= 70, "C", TRUE, "F")

ROUND

Syntax: ROUND(x)

Rounds a floating-point number to the nearest integer.

x = ROUND(3.7)      ' x = 4
x = ROUND(3.2)      ' x = 3

LIKE Operator (V27)

Syntax: stringExpr LIKE pattern$

Wildcard pattern matching using Windows PathMatchSpecA. Returns TRUE if the string matches the pattern.

IF filename LIKE "*.pb" THEN PRINT "BASIC file"
IF name LIKE "test*" THEN PRINT "starts with test"

PRINT USING (V27)

Syntax: PRINT USING mask$; expr

Formatted output using the FORMAT$ path. The mask is applied to the expression before output.

PRINT USING "000"; 42        ' Prints "042"
PRINT USING "###.##"; 3.5    ' Future: prints "  3.50"

FORMAT$ with Masks (V26/V27)

Syntax: FORMAT$(n [, "mask"])

Returns a formatted string. With a mask, formats the number according to the mask pattern.

s = FORMAT$(42, "000")      ' s = "042"
s = FORMAT$(1234)            ' s = "1234" (basic numeric)
V26 adds first-pass picture mask support. Full PowerBASIC mask parity remains future work.

BUILD$

Syntax: BUILD$(expr1, expr2, ...)

Builds a string by concatenating all arguments.

s = BUILD$("x=", FORMAT$(x, "000"), ", y=", FORMAT$(y, "000"))

CLIP$

Syntax: CLIP$(s$)

Removes leading and trailing whitespace. Similar to LTRIM$(RTRIM$(s$)).

s = CLIP$("  hello  ")      ' s = "hello"

RETAIN$

Syntax: RETAIN$(s$, chars$)

Keeps only characters from s$ that appear in chars$.

s = RETAIN$("a1b2c3", "0123456789")   ' s = "123"

SHRINK$

Syntax: SHRINK$(s$)

Collapses multiple consecutive spaces into a single space.

s = SHRINK$("a    b  c")    ' s = "a b c"