Using the IIF Function in FoxBASE+ or FoxPro

Last reviewed: October 18, 1995
Article ID: Q88885
The information in this article applies to:
  • Microsoft FoxBASE+ for MS-DOS, versions 1.21 and 2.1
  • Microsoft FoxPro for MS-DOS, versions 1.0, 1.01, 1.02, 2.0, 2.5x, 2.6x
  • Microsoft FoxPro for Windows, versions 2.5x, 2.6x
  • Microsoft Visual FoxPro for Windows, version 3.0

SUMMARY

The IIF (Immediate If) function returns one of two expressions, depending on the value of a logical expression. When IIF evaluates a logical expression, if the logical expression evaluates to a logical true value (.T.), IIF returns the value of the first expression. If the logical expression evaluates to a logical false value (.F.), IIF returns the value of the second expression.

MORE INFORMATION

The IIF function can be used in place of the IF ... ENDIF structure for simple conditional expressions. This function is especially useful in CREATE REPORT or CREATE LABEL commands to conditionally specify field contents. In a FoxBASE+ or FoxPro report or label, the IIF function is the only conditional statement allowed. The IIF function also executes considerably faster than the equivalent IF ... ENDIF statements.

Examples

   STORE 10 TO Num
   Char = IIF(Num > 9, STR(Num, 2), STR(Num, 1))
   ? Char
* This code returns 10.

   Store 9 to Num
   Char = IIF(Num>9, STR(Num, 2), STR(Num, 1))
   ? Char
* This code returns 9.


Additional reference words: VFoxWin FoxWin FoxDos 1.00 2.00 1.21 2.10 2.50
2.50a 2.50b 2.60 2.60a 1.x 2.x 3.00
KBCategory: kbprg
KBSubcategory: FxprgGeneral


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 18, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.