Wrox Programmer Forums
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 12th, 2007, 04:41 AM
Authorized User
 
Join Date: May 2007
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default IIf

hi all :)

what is the use of IIf?


 
Old June 12th, 2007, 11:31 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

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.
Code:
   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"
   Else
      s = "It is False"
   End If
 
Old June 13th, 2007, 12:34 AM
Authorized User
 
Join Date: May 2007
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thank you very much Brian

 
Old June 21st, 2007, 12:24 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
http://www.learntoprogramnow.com
How to use a forum to help solve problems





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with IIF thork1 Access 1 March 25th, 2008 06:42 AM
IIf problem Vince_421 Access 1 June 1st, 2006 11:35 AM
Query with IIF canmex Access 14 March 7th, 2006 03:07 AM
Question with iif Enoch Access 5 December 8th, 2005 04:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.