Library code snippets
Create an IIF statement in VBScript
Many ASP developers are also Visual Basic developers, and as such, we often have
to shift gears between the two, remembering (or trying to remember, at least)
which features exist in one and not the other. Differences in error trapping and
class definitions are among the more well-recognized, but there are many more
subtle discrepancies. For example, VB has a handy function, IIf, which allows
you to collapse several lines of Boolean logic into a single expression, like
this:
blnFoo1 = True
As you can see, the first parameter represents the expression to evaluate. The
second parameter is the result to return if the expression evaluates to True,
while the third parameter is the result to return if the expression evaluates to
False. VBScript, unfortunately, doesn't support this function, but you can
easily write your own equivalent, like this:
blnFoo2 = False
MsgBox IIf(blnFoo1 = blnFoo2, "The same!", "Different!")
Public Function IIf(blnExpression, vTrueResult, vFalseResult)
If blnExpression Then
IIf = vTrueResult
Else
IIf = vFalseResult
End If
End Function
Related articles
Related discussion
-
Help to Call ASP function from onclick event in HTML to pass an array
by vka (0 replies)
-
Binary Studio | software development outsourcing Ukraine
by shane124 (4 replies)
-
Variable In Vb.Net
by chia (0 replies)
-
ideas in building a captive portal
by sjranjan (2 replies)
-
How to debug classic ASP pages during AJAX calls in ASP.NET website
by andwan0 (0 replies)
Related podcasts
-
Scott Guthrie
Scott catches up with Scott Guthrie in an interview covering Ajax, Asp 2.0, extender controls, CSS adapters and more.
the iif (along with tons of others such as left and right) are still available, they are just hidden
microsoft.visualbasic has all of those goodies that we've come to know and love.
enjoy
This thread is for discussions of Create an IIF statement in VBScript.