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
-
Calling a function from ASP code
by dunk00 (3 replies)
-
GridView HyperLinkField Problem
by Paul2 (0 replies)
-
looking for help on asp
by cladironbeard (2 replies)
-
simple vb to c#, help please
by lksath (1 replies)
-
Binary Studio | software development outsourcing Ukraine
by Hexfinity (2 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.
Events coming up
-
Aug
27
Model-View-Presenter (MVC) in ASP.NET
San Francisco, United States
Model-View-Presenter (MVC) in ASP.NET Presenter Clayton Peddy, Terrace Software, Inc. Details TBD
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.