IIF function
Purpose: IIF returns the TRUECase or FALSECase value based on the state of the Boolean expression
Syntax: RetVal# = IIF(Expression, TRUECase, FALSECase) Parameters:
Return Value:
|
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:
Return Value:
|
Example:
DIMa, b, c$ a=1b=2"a = 1 b = 2"c$=IIF$(a=b,"TRUE","FALSE")"IIF$(a = b, TRUE, FALSE) returned ", c$ c$=IIF$(a <> b,"TRUE","FALSE")"IIF$(a <> b, TRUE, FALSE) returned ", c$ c$=IIF$(a < b,"TRUE","FALSE")"IIF$(a < b, TRUE, FALSE) returned ", c$ c$=IIF$(a > b,"TRUE","FALSE")"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:
DIMbuf1$, buf2$, str1$ buf1$="1898-10-1"buf2$="1898-8-10""buf1 = 1898-10-1 b = 1898-8-10"str1$=IIF$(strcmp(buf1$, buf2$)=-1,"TRUE","FALSE")IFstr1$="TRUE"THEN"buf1 less than buf2"ENDIFIFstr1$="FALSE"THEN"buf1 not less than buf2"ENDIF