IIF function

Purpose:

IIF returns the TRUECase or FALSECase value based on the state of the Boolean Expression.

Syntax:

RetVal = IIF(Expression, TRUECase, FALSECase)

Return Value:

  • Data type: DOUBLE
    RetVal If the Boolean Expression is TRUE, the number in TRUECase is returned otherwise the return is the FALSECase number.

Parameters:

  • Data type: BOOL
    Expression Boolean value derived from a comparison of numbers.
  • Data type: Number
    TRUECase Must be a number.
  • Data type: Number
    FALSECase Must be a number.

Example:

DIM A, B, C

A = 5
B = 6
C = IIF(A > B, 100, 200)

PRINT C

Result:

The condition A > B is FALSE, therefore the FALSECase, 200, is displayed.

 200

IIF$ function

Purpose:

IIF$ returns the TRUECase or FALSECase STRING based on the state of the Boolean Expression.

Syntax 1:

RetStr = IIF$(Expression, TRUECase, FALSECase)

Return Value:

  • Data type: STRING
    RetStr If the Boolean Expression is TRUE, the string in TRUECase is returned otherwise the return is the FALSECase string.

Parameters:

  • Data type: BOOL
    Expression Boolean value derived from a comparison of numbers.
  • Data type: STRING
    TRUECase Must be a string literal or variable.
  • Data type: STRING
    FALSECase Must be a string literal or variable.

Example:

DIM a, b, c$

a = 1
b = 2

PRINT "a = 1  b = 2"

c$ = IIF$(a = b, "TRUE", "FALSE")
PRINT "IIF$(a = b, TRUE, FALSE) returned ", c$

c$ = IIF$(a <> b, "TRUE", "FALSE")
PRINT "IIF$(a <> b, TRUE, FALSE) returned ", c$

c$ = IIF$(a < b, "TRUE", "FALSE")
PRINT "IIF$(a < b, TRUE, FALSE) returned ", c$

c$ = IIF$(a > b, "TRUE", "FALSE")
PRINT "IIF$(a > b, TRUE, FALSE) returned ", c$

Result:

a = 1  b = 2
IIF$(a = b, TRUE, FALSE) returned FALSE
IIF$(a <> b, TRUE, FALSE) returned TRUE
IIF$(a < b, TRUE, FALSE) returned TRUE
IIF$(a > b, TRUE, FALSE) returned FALSE

The following example shows how IIF$ can be used to compare strings.

Example:

DIM buf1$, buf2$, str1$
 
buf1$ = "ABCDEFGHI"
buf2$ = "JKLMNOPQR"
 
PRINT "buf1$ = ABCDEFGHI  buf2$ = JKLMNOPQR"
 
str1$ = IIF$(strcmp(buf1$, buf2$) = -1, "TRUE", "FALSE")

IF str1$ = "TRUE" THEN
  PRINT "buf1$ is less than buf2$"
END IF

IF str1$ = "FALSE" THEN
  PRINT "buf1$ is not less than buf2$"
END IF

Result:

buf1$ = ABCDEFGHI  buf2$ = JKLMNOPQR
buf1$ is less than buf2$