OpenNTF.org - Immediate If
My Links (Not logged in)
Code Bin Search
 
Hosted by Prominic.NET
Rate This Code
5 - brilliant stuff
4 - very nice
3 - average
2 - needs work
1 - bad
   OpenNTF Code Bin
Edit Document Code By Date > Code Document
About This Code
Brief Description:
Immediate If  
Rating:
Rating: 1 , Number of votes: 1 
Contributor:
Mike Mortin 
Category:
Lotusscript 
Type:
Miscellaneous 
Notes Version:
R6.x, R8.x, R7.x 
Last Modified:
03 Nov 2008 
OpenNTF Disclaimer

All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.

Code / Description
Function IIf (condition As Variant, trueCondition As Variant, falseCondition As Variant) As Variant

' such a basic function for all other programming languages ... stands for "Immediate IF"
' posted to http://www.openntf.org/projects/codebin/codebin.nsf/CodeBySubCategory/328BED8C4AB8E446862574EF0068734A
' written by Mike Mortin
If condition Then
If Isobject(TrueCondition) Then
Set IIf = trueCondition
Else
IIf = trueCondition
End If
Else
If Isobject(TrueCondition) Then
Set IIf = falseCondition
Else
IIf = falseCondition
End If
End If
End Function

Usage / Example
I am not the first to write this I'm sure, but it is so handy it should be a standard in LS
This replaces long nasty lines of mostly redundant if/then/else statements by turning 5 lines of code into 1

... turn this
' if not an employee, assume consultant
If IsEmployee(empNo) then
set manager = GetManager(empNum)
Else
set manager = GetFunctionalManager(consNum)
End If

... into this
set manager = Iif( IsEmployee(empNo), GetManager(empNum), GetFunctionalManager(consNum) )
...

The only catch is that the 2nd and 3rd parameters are evaluated in order to be passed into the function. Sinze all 3 statements are evaluated inorder to be passedin, if on of those statements generates an error, you've got problems and will likely have to go back to the if/then/else statement.
Example:

If GetManager(...) generates an error when a non-valid empNo is passed in, then your Iif(...) statement will error out also. Here, you'd have to use the long format so GetManager(...) is only evaluated if IsEmployee(...) = true
 Comments

No documents found

 Add your comment!