Quantcast IIf - Visual Basic Wiki
Recent changes Random page
GAMING
Technology
 
Gaming
Entertainment
Science Fiction
Biggest wikis
Hobbies
Music
See more...

IIf

From Visual Basic Wiki

Jump to: navigation, search

Contents

[edit] Function: IIf

IIf makes expressions easier. PHP comparison to VB:

// PHP
$data = $expr ? truePart : falsePart
' VB
Data = IIf(expr, truePart, falsePart)

[edit] Usage

IIf(Expression, TruePart, FalsePart)

[edit] Howto

If expression is true TruePart is returned, otherwise FalsePart is returned.

[edit] Example

' Standard boolean
Dim StdBool As Long, VbBool As Boolean
VbBool = False
StdBool = IIf(VbBool, 1, 0)

[edit] Notes

If you put calls to functions in the True or False parts those functions will be called even if the results of that function is not returned by the condition. The IIf is a function and each part is evaluated and the results is passed in and based on the condition expression the result of the true or false parts are returned.

In VB.NET this function returns an Object type and if you have option strict turned on, you will need to convert the results to the actual type of the variable you are trying to put the data into.

Rate this article:
Share this article: