TRUE and FALSE system variables

Purpose:

BCX and C/C++ use an integer value of 1 for TRUE and an integer value of 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:

  • Data type: STRING
    RetStr True or False

Parameters:

  • Data type: INTEGER
    Expression Variable, literal or an expression to be evaluated.

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:

  • Data type: INTEGER
    RetVal If Expression is not equal to 0, 1 is returned; otherwise 0.

Parameters:

  • Data type: Scalar
    Expression String or numeric expression to be evaluated.

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

' Initialize the c$ 
c$ = "El gato esta aqui!"

' Check if z is initialized. 
?  CBOOL(z) ' Should be FALSE

' Short-circuit z to c$(initialized) 
z = c$

' Check again if z is initialized. 
?  CBOOL(z) ' Should be TRUE 

' Unplug the LPSTR (once again uninitialized) 
CLEAR(z)

?  CBOOL(z) ' Should be FALSE

KEYPRESS

Result:

0
1
0

ISTRUE and NOTZERO functions

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:

  • Data type: INTEGER
    RetVal If IdVar is not equal to 0, 1 is returned; otherwise 0.

Parameters:

  • Data type: Scalar
    IdVar Object to be evaluated whether it is not equal to 0.

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 and ISZERO functions

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:

  • Data type: INTEGER
    RetVal If IdVar is equal to 0, the return value is 1, otherwise 0.

Parameters:

  • Data type: Scalar
    IdVar Object to be evaluated whether it is equal to 0.

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 and NOTNULL functions

Purpose:

ISNULL and NOTNULL evaluate a string to determine if the string is empty.

Syntax 1:

RetVal = ISNULL(String AS STRING)

Return Value:

  • Data type: INTEGER
    RetVal will be 1 if String$ is empty and equal to 0 if it has contents.

Parameters:

  • Data type: STRING
    String to be determined whether it is empty.

Syntax 2:

RetVal = NOTNULL(String AS STRING)

Return Value:

  • Data type: INTEGER
    RetVal will be 1 if String$ has contents and equal to 0 if it is empty .

Parameters:

  • Data type: STRING
    String to be determined whether it is empty.

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 ...