Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

In List Syntax

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
Hello all....I'm venturing out into the world of scripting! Actually one of my co-workers is and I was looking at one of his scripts and there's a string of OR statements. I'm pretty sure that there's a way to do a "In List" in VBScript, but when I search for that I get hundreds of threads.

Can someone tell me how to replace a string of ORs with a single "In [List of criteria]"?

Thanks!

Leslie

 
There is an In() option in SQL but as far as I know there isn't in VBScript, you try the Select statement:

Code:
myVar = 3

Select Case myVar
	Case 1
		Wscript.Echo "A single value"
	Case 2,3,5
		Wscript.Echo "Multiple Values"

	Case Else
		Wscript.Echo "any other value"
End Select
 
What is he testing for?

One way to do away with the OR's would be a Select statement

Select Case SomeVariable
Case "abc","def","wxy"
'do something
Case "hij", "klm", "z"
'do something else
End Select

We'd really need to see what he is doing to see what may work better.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Looks like I was slow in my post and BillDoor already mentioned the Select Case so here is a dictionary example...again it would depend on what you are working with.

Dim objDict : Set objDict = CreateObject("Scripting.Dictionary")
objDict.Add "abc", ""
objDict.Add "def", ""
objDict.Add "xyz", ""

If objDict.Exists("abc") Then
'do something
Else
'do something else
End If

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
I think the Case Statement will work best....he's looking at specific computer names to determine which printer should be installed. Right now it's:

if computername = 'INFTCH03' OR ComputerName = 'INFTCH06' OR etc....

thanks for the input!

leslie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top