Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VBScript
Expertise: Beginner
Nov 5, 2003

Use the Immediate If Function in VBScript

Visual Basic includes the Immediate If function (IIf), but VBScript (VBS) does not. However, you can copy this code to VBS to allow the IIf function to be used:

'VB Function not included in VBS
Function IIf(Expression, TruePart, FalsePart)
	If Expression = True Then
		If IsObject(TruePart) Then
			Set IIf = TruePart
		Else
			IIf = TruePart
		End If
	Else
		If IsObject(FalsePart) Then
			Set IIf = FalsePart
		Else
			IIf = FalsePart
		End If
	End If
End Function
The function can return both objects and basic data types. Heres a sample function from an ASP page that calls the IIf function:

' Return a True or False value for a checkbox
Function CheckBoxValue(Name)
	CheckBoxValue = _
		IIf(Request.Form(Name) = "on", True, False)
End Function
Conrad Sollitt
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap