Login | |
|
 |
VBScript runtime error: Subscript out of range - 7/4/2007 6:50:42 PM
|
|
 |
|
| |
nicci
Posts: 5
Score: 0
Joined: 7/4/2007
Status: offline
|
When I execute the script below I get Following error (with parameters) "D:\Data\My_Progs\TA_Control_Center\Tools\UpdaterSoft\_Other\Rtask(beta).vbs(15, 3) Microsoft VBScript runtime error: Subscript out of range" That is on the first line of code inside the for next loop "If InStr(LCase(args.Item(k)),"/f:") > 0 then". I also tried replacing the "If's" inside the loop with "Select Case" but it generates the same error When I add "On Error Resume Next" it works perfectly. I can't find any fault in the source or am I looking over it? CODE: Set args = WScript.Arguments dissablefilter= 0 '0 = show all '1 = show only disabled '2 = show only enabled WScript.Echo "args: " & args.Count '# Read & process arguments If args.Count>0 Then For k = 0 To args.Count If InStr(LCase(args.Item(k)),"/f:") > 0 then filtr=mid(args.Item(k),4) ElseIf instr(LCase(args.Item(k)),"/ou:")>0 then ou=ou & "ou=" & mid(args.Item(k),5) & ", " ElseIf instr(LCase(args.Item(k)),"/dc:")>0 then dc=dc & "dc=" & mid(args.Item(k),5) & ", " ElseIf instr(LCase(args.Item(k)),"/cn:")>0 then cn=cn & "cn=" & mid(args.Item(k),5) & ", " ElseIf instr(LCase(args.Item(k)),"/disfilt:")>0 then dissablefilter= mid(args.Item(k),10) ElseIf instr(LCase(args.Item(k)),"/list:")>0 then PClist= mid(args.Item(k),7) end if Next Wscript.Echo "ou: " & ou Wscript.Echo "cn: " & cn Wscript.Echo "dc: " & dc Wscript.Echo "filter: " & filtr Wscript.Echo "dissablefilter: " & dissablefilter Wscript.Echo "PClist: " & PClist Wscript.Echo End if WScript.Quit
|
|
| |
|
|
|
 |
RE: VBScript runtime error: Subscript out of range - 7/5/2007 12:13:48 AM
|
|
 |
|
| |
ebgreen
Posts: 5035
Score: 31
Joined: 7/12/2005
Status: online
|
Your args are in the proper format to use the Named arguments collection. Then you would not need to use any counts. Look at the WSH docs for Named Arguments.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
|
|