TRUE or FALSE system variables
BCX and C/C++ use an integer value of 1 for TRUE and 0 for FALSE.
BOOL$ function
Purpose: BOOL$ returns a string; TRUE, if the expression evaluates to a nonzero value; FALSE, if the expression evaluates to a zero.
Syntax: RetStr = BOOL$(Expression AS INTEGER) Return Value: Parameters:
|
Example:
DIM RetStr$ DIM int1%, int2% int1% = 1 int2% = 2 RetStr$ = BOOL$(int1% <> int2%) PRINT RetStr$ int1% = -1 RetStr$ = BOOL$(int1%) PRINT RetStr$ int1% = 0 RetStr$ = BOOL$(int1%) PRINT RetStr$
Result:
True True False
CBOOL function
Purpose: The CBOOL function returns the evaluation of an expression as a Boolean. If the expression evaluates to a nonzero value, CBOOL returns 1; otherwise, it returns 0.
Syntax: RetVal = CBOOL(Expression) Return Value:
Parameters:
|
Example 1:
DIM int1%, int2%, RetVal% DIM str1$, str2$ int1% = 1 int2% = 2 RetVal% = CBOOL(int1% <> int2%) PRINT RetVal% int1% = 0 RetVal% = CBOOL(int1%) PRINT RetVal% str1$ = "1" str2$ = "2" RetVal% = CBOOL(str1$ = str2$) PRINT RetVal%
Result:
1 0 0
Example 2:
Here is is a example using CBOOL with strings and a pointer.
DIM RAW c$, z AS LPSTR ' Init the c$ c$ = "El gato esta aqui!" ' Check if z is used or not...(uninitialized)? ? CBOOL(z) ' Should be FALSE ' Short-circuit z to c$(initialized) z = c$ ? CBOOL(z) ' Should be TRUE ' Unplug the LPSTR (once again uninitialized) CLEAR(z) ? CBOOL(z) ' Should be FALSE KEYPRESS
Result:
0 1 0
ISTRUE function and NOTZERO function
Purpose: ISTRUE and NOTZERO evaluate whether a scalar object is not equal to 0.
Syntax 1: RetVal = ISTRUE(IdVar)Syntax 2: RetVal = NOTZERO(IdVar) Return Value:
Parameters:
|
Example:
$BCXVERSION "7.5.3" DIM Number% Number% = 1 ? PRINT "ISTRUE ", Number%, ISTRUE(Number%) PRINT "NOTZERO ", Number%, NOTZERO(Number%) Number% = -1 ? PRINT "ISTRUE ", Number%, ISTRUE(Number%) PRINT "NOTZERO ", Number%, NOTZERO(Number%) Number% = 0 ? PRINT "ISTRUE ", Number%, ISTRUE(Number%) PRINT "NOTZERO ", Number%, NOTZERO(Number%)
Result:
ISTRUE 1 1 NOTZERO 1 1 ISTRUE -1 1 NOTZERO -1 1 ISTRUE 0 0 NOTZERO 0 0
Remarks:
☞ When a static or dynamic string is used
as the Expression, a ‘Value at address’ operator (*) must be used
immediately preceding the Expression, for example,
$BCXVERSION "7.5.3" DIM Str1$ ' a dynamically allocated string DIM Str2$ [20] AS CHAR ' a statically allocated string Str1$ = "A dynamic string" PRINT "ISTRUE ", ISTRUE(*Str1$) Str1$ = "" PRINT "ISTRUE ", ISTRUE(*Str1$) Str2$ = "A static string" PRINT "ISTRUE ", ISTRUE(*Str2$) Str2$ = "" PRINT "ISTRUE ", ISTRUE(*Str2$)
Result:
ISTRUE 1 ISTRUE 0 ISTRUE 1 ISTRUE 0
Within an IF ... THEN selection statement, NOTZERO and ISTRUE can be used without parentheses surrounding the evaluated expression. For example
$BCXVERSION "7.7.2" DIM Number% Number% = 1 IF NOTZERO Number% THEN PRINT "MyFlag equals one." END IF
Result:
MyFlag equals one.
These functions can help improve the meaning of expressions, for example, while the following is completely legitimate
IF *pMyString THEN DoSomething()
this is more explicit.
IF NOTZERO(*pMyString) THEN DoSomething()
'----------------------------------------------- ' TRUTH TABLE '----------------------------------------------- ' TEST Expression Result Synonym '----------------------------------------------- ' ISTRUE = 0 0 NOTZERO ' ISTRUE <> 0 1 NOTZERO ' ISFALSE = 0 1 ISZERO ' ISFALSE <> 0 0 ISZERO '-----------------------------------------------
ISFALSE function and ISZERO function
Purpose: ISFALSE and ISZERO evaluate a scalar object by determining whether the value of IdVar is equal to 0.
Syntax 1: RetVal = ISFALSE(IdVar)Syntax 2: RetVal = ISZERO(IdVar) Return Value:
Parameters:
|
Example:
$BCXVERSION "7.5.3" DIM Number% Number% = 1 ? PRINT "ISFALSE ", Number%, ISFALSE(Number%) PRINT "ISZERO ", Number%, ISZERO(Number%) Number% = -1 ? PRINT "ISFALSE ", Number%, ISFALSE(Number%) PRINT "ISZERO ", Number%, ISZERO(Number%) Number% = 0 ? PRINT "ISFALSE ", Number%, ISFALSE(Number%) PRINT "ISZERO ", Number%, ISZERO(Number%)
Result:
ISFALSE 1 0 ISZERO 1 0 ISFALSE -1 0 ISZERO -1 0 ISFALSE 0 1 ISZERO 0 1
Remarks:
☞ When a static or dynamic string is used
as the Expression, a ‘Value at address’ operator (*) must be used
immediately preceding the Expression, for example,
$BCXVERSION "7.5.3" DIM Str1$ ' a dynamically allocated string DIM Str2$ [20] AS CHAR ' a statically allocated string Str1$ = "A dynamic string" PRINT "ISFALSE ", ISFALSE(*Str1$) Str1$ = "" PRINT "ISFALSE ", ISFALSE(*Str1$) Str2$ = "A static string" PRINT "ISFALSE ", ISFALSE(*Str2$) Str2$ = "" PRINT "ISFALSE ", ISFALSE(*Str2$)
Result:
ISFALSE 0 ISFALSE 1 ISFALSE 0 ISFALSE 1
Within an IF ... THEN selection statement, ISFALSE and ISZERO can be used without parentheses surrounding the evaluated expression. For example
$BCXVERSION "7.7.2" DIM Number% Number% = 0 IF ISZERO Number% THEN PRINT "MyFlag equals zero." END IF
Result:
MyFlag equals zero.
ISNULL function and NOTNULL function
Purpose: ISNULL and NOTNULL evaluate a string to determine if the string is empty.
Syntax 1: RetVal = ISNULL(String AS STRING) Return Value:
Parameters:
|
Syntax 2: RetVal = NOTNULL(String AS STRING) Return Value:
Parameters:
|
Example:
$BCXVERSION "7.7.7" DIM Str1$ ' a dynamically allocated string DIM Str2$ [20] AS CHAR ' a statically allocated string Str1$ = "A dynamic string" PRINT "ISNULL ", ISNULL(Str1$) PRINT "NOTNULL ", NOTNULL(Str1$) ? Str1$ = "" PRINT "ISNULL ", ISNULL(Str1$) PRINT "NOTNULL ", NOTNULL(Str1$) ? Str2$ = "A static string" PRINT "ISNULL ", ISNULL(Str2$) PRINT "NOTNULL ", NOTNULL(Str2$) ? Str2$ = "" PRINT "ISNULL ", ISNULL(Str2$) PRINT "NOTNULL ", NOTNULL(Str2$)
Result:
ISNULL 0 NOTNULL 1 ISNULL 1 NOTNULL 0 ISNULL 0 NOTNULL 1 ISNULL 1 NOTNULL 0
Remarks:
IF ISNULL(A$) THEN ...
is an alternative to
IF A$ = "" THEN ...
and
IF NOTNULL(A$) THEN ...
is an alternative to
IF A$ <> "" THEN ...