Posted By

Scooter on 05/19/08


Tagged

control structures


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

wizard04
asifrizvigmailcom


Immediate If


 / Published in: ASP
 

URL: http://reusablecode.blogspot.com/2008/04/immediate-if.html

The iif() function in Visual Basic is sometimes more convenient than a full-blown if...then...else... control structure. Oddly enough, the function does not exist in VBScript.

  1. <%
  2. ' Copyright (c) 2008, reusablecode.blogspot.com; some rights reserved.
  3. '
  4. ' This work is licensed under the Creative Commons Attribution License. To view
  5. ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or
  6. ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
  7. ' 94305, USA.
  8.  
  9. ' The iif function from Visual Basic that is missing from VBScript.
  10. function IIf(expression, truecondition, falsecondition)
  11. if cbool(expression) Then
  12. IIf = truecondition
  13. else
  14. IIf = falsecondition
  15. end if
  16. end function
  17. %>

Report this snippet  

You need to login to post a comment.