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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error: invalid index

Status
Not open for further replies.

TheALL

Technical User
Jul 19, 2004
14
IT
hi,
i build a vb script to install a printer if not exist, but on some windows 7 (not all windows 7 client) i have this error:


Error: Invalid Index
Code: 8002000B
Origin: SWbemObjectEx


The portion ocde with error is this:
Code:
........
sub GroupPrinterpadova1 ()
Set Printers = WshNetwork.EnumPrinterConnections
For i = 0 to Printers.Count - 1 Step 2
	if Printers.Item(i+1)="\\srv-dc-01\PDPRINTER01 (RICOH Aficio MP 161 PCL6)" then
	PrinterPD1=1
        end if
next
if PrinterPD1<>1 then
WshNetwork.AddWindowsPrinterConnection "\\" & printpadova & "\PDPRINTER01"
end if
end sub
..............

i put some echo to see where exactly the error start and:

1)if i change this line:
Set Printers = WshNetwork.EnumPrinterConnections
into
Set Printers = WshNetwork.EnumPrinterConnections()
the script go on , to second if statement

and if i insert an else:
Code:
if PrinterPD1<>1 then
WshNetwork.AddWindowsPrinterConnection "\\" & printpadova & "\PDPRINTER01"
end if

into

if PrinterPD1<>1 then
WshNetwork.AddWindowsPrinterConnection "\\" & printpadova & "\PDPRINTER01"
[b]else[/b]
end if

the script go on and done all but when arrive at end sub,i have the error.

then i try to delete a part of code
2)if i delete cycle for--next, all go well(the content of cycle for not matter at all)
3)if i delete the second if --- enf if, all go well

someone could explain me?
thx
 
>For i = 0 to Printers.Count - 1 Step 2
[tt]For i = 0 to Printers.Count - [red]2[/red] Step 2[/tt]
 
nope,
the error still remain for windows 7

i think there is a patch or software that scan the correct scripting form.
Infact the script is execute without error until "end sub".
i Think less some correct exit form from sub or from cycle for-next.


 
No, that for loop upper bound change won't cue the problem, no. That's just a setting that do not rely on the even-ness of .count which os should take care implicitly as even.
 
printer.counts in the real it starts from -1 and add two line for each printer, but -1 is the port and 0 is the name of the first printer
Then i must start from 0 (the name) and progress by two (step 2)

what do you suggest?

maybe i can change the script but i'm curious to understand this error
 
error found, simply declare i of Printers.Item(i)


Code:
........
sub GroupPrinterpadova1 ()
dim i
[code]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top