Posted July 2, 2008 and filed under Technology    tags:  ,

While writing code in Visual Basic.NET I frequently use the IIF Function.  Reading the MSDN definition of IIF tells you that IIF returns one of two objects, depending on the evaluation of an expression.  Quite the handy function indeed.  Recently I was writing some VBScript code and wanted to use IIF but found it doesn’t exist in VBScript.  Well a quick look around and I found a function at 4guysfromrolla that can be used in VBScript to satisfy this need.

Function IIF(psdStr, trueStr, falseStr)
  if psdStr then
    iif = trueStr
  else 
    iif = falseStr
  end if
End Function

Using this syntax allows the following function call to work great:

strStatus = IIF(Process.IsAlive,"available","unavailable")

How many of you guys use IIF in your code writing?

If you liked this article why not share it with others?

Kick it up to DotNetKicks.com

Add comment


(Will show your Gravatar icon)

biuquote
Loading