IIf Function


IIf Function

Class

Microsoft.VisualBasic.Interaction

Syntax

     Dim result As Object = IIf(expression, truePart, falsePart) 


expression (required; Boolean)

Expression to be evaluated


truePart (required; any value or expression)

Expression or value to return if expression is true


falsePart (required; any value or expression)

Expression or value to return if expression is False

Description

The IIf function returns one of two results, depending on whether expression evaluates to true or False.

Usage at a Glance

  • The IIf function, as shown in the syntax listed above, is generally equivalent to:

         If expression Then         Return truePart     Else         Return falsePart     End If 

  • truePart and falsePart can be variables, constants, literals, expressions, or function calls. expression can also be built from many complex elements, as long as it ultimately results in a Boolean value.

  • Both truePart and falsePart are fully evaluated before they are considered as results for the IIf statement. If they contain function calls, those functions will be called, even in the part that is not returned by the IIf function. For instance, in the statement:

         result = IIf(tempOnly, ProcessFile(tempFileName), _        ProcessFile(mainFileName)) 

    both calls to ProcessFile will always be performed, regardless of the value of tempOnly. However, the return value from only one of the calls will be returned from the IIf function.

See Also

If...Then...Else Statement




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net