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
-
Header and Footer in Web page print
by fhajaj (4 replies)
-
help me to get simple requirement
by Slicksim (1 replies)
-
Gridview -> Template Field -> Button
by antti.simonen (1 replies)
-
Classic ASP : Page expires
by chezhian_in05 (0 replies)
-
ASP VS PHP
by paulfp (9 replies)
Related podcasts
-
ASP.NET Caching and Performance
Steve Smith, owner of ASP Alliance and Lake Quincy Media joins us today to teach us about some hidden gems in ASP.NET caching and performance. Steve’s expertise in this area comes from first-hand experience as Lake Quincy’s ad system serves over 60 requests per second and handles over 150 million...
Related jobs
-
Microsoft .Net Architect
in AMSTERDAM (€50K-€90K per annum) -
Microsoft Dynamics CRM Technical Consultant
in Netherlands (€50K-€90K per annum) -
Technical Support Engineer EMEA
in Reading (£50K-£50K per annum) -
Solutions Engineer
in Reading (£50K-£60K per annum)
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.