IIF.md 2.8 KB

IIF function

Purpose: IIF returns the TRUECase or FALSECase value based on the state of the Boolean expression


 Syntax 1:

 RetVal# = IIF(Expression, TRUECase, FALSECase)

 Parameters:

  • RetVal# contains the returned TRUECase or FALSECase double value based on the state of the Boolean expression.
  • Expression Boolean expression derived from a comparison of numbers.
  • TRUECase Must be a number.
  • FALSECase Must be a number.

Example:


 DIM A, B, C

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

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

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)

 Parameters:

  • RetStr$ contains the returned TRUECase or FALSECase string based on the state of the Boolean expression.
  • Expression Boolean expression derived from a comparison of numbers.
  • TRUECase Must be a string literal or variable.
  • 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$

Produces this output:


 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$ = "1898-10-1"
 buf2$ = "1898-8-10"
  
 PRINT "buf1 = 1898-10-1  b = 1898-8-10"
  
 str1$ = IIF$(strcmp(buf1$, buf2$) = -1, "TRUE", "FALSE")
 
 IF str1$ = "TRUE" THEN
   PRINT "buf1 less than buf2"
 END IF
 
 IF str1$ = "FALSE" THEN
   PRINT "buf1 not less than buf2"
 END IF