p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Beginning VB 6 (http://p2p.wrox.com/forumdisplay.php?f=75)
-   -   IIf (http://p2p.wrox.com/showthread.php?t=58976)

umeshtheone June 12th, 2007 04:41 AM

hi all :)

what is the use of IIf?

BrianWren June 12th, 2007 11:31 AM

You really can find all of the answers to the basic questions you have been asking in VB Help...

IIf is a single-statement If for returning a value. It takes three arguments. If the first argument is true, it returns the 2nd argument. If the 1st argument is false, it returns the 3rd argument.

   Dim s as String

   s = IIf( (2 + 2) = 4, "It is True", "It is False")

   ' The above results in exactly the same result as the below.

   If (2 + 2) = 4 Then
      s = "It is True"
      s = "It is False"
   End If

umeshtheone June 13th, 2007 12:34 AM

thank you very much Brian

woodyz June 21st, 2007 12:24 AM

Well... actually, the value of the immediate if (IIf) is for use in an expression or as an argument being passed to a parameter of a procedure.

Note that IIf itself is a function which accepts 3 parameters and returns a value. Although it seems as if it is the same thing as a regular If...Else block, its real benefit is that it returns a value. Each argument itself can also be an expression, and this brings a great deal of power to this little intrinsic function. However, make sure all the arguments will be valid in all cases because all three arguments must be resolved before they are passed on to the IIf function, just like with any other function. In other words, regardless if the first argument is true or false, both the 2nd and 3rd arguments are going to be processed before their values are passed into the function.

Woody Z
How to use a forum to help solve problems

All times are GMT -4. The time now is 01:19 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.