YFridman Posted February 18, 2015 Share Posted February 18, 2015 (edited) Does anyone know how to determine the size of 2 dimensional array? the following script works, until $x becomes larger than the size of the array. Then it errors out. I would prefer a more graceful exit. $aPrinterList = _EnumPrinterProperties("*") $x=-1 While 1 $x=$x+1 $queue=$aPrinterList[$x][6] If @error<>0 then ExitLoop ;<--------------------------------------------------------- If $queue=$oldPrinter then _RemovePrinter($oldPrinter) _AddWindowsPrinterConnection($newPrinter) If $aPrinterList[$x][18]="True" Then _SetDefaultPrinter($newPrinter) EndIf WEnd Edited February 18, 2015 by YFridman Link to comment Share on other sites More sharing options...
Gianni Posted February 18, 2015 Share Posted February 18, 2015 Ubound() ? Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 18, 2015 Moderators Share Posted February 18, 2015 (edited) Your logic is off on your condition statements too. Does $aPrinterList[$x][18] return a string? That's what you're comparing it too, more likely it returns a boolean. You're checking @error on something that cannot return an "@error". Global $aPrinterList = _EnumPrinterProperties("\\*") If Not IsArray($aPrinterList) Then Exit 2 EndIf ; validate ubound 2nd dim If (UBound($aPrinterList, 2) - 1) < 18 Then Exit 3 EndIf Global $queue, $oldPrinter, $newPrinter For $x = 0 To UBound($aPrinterList, 1) - 1 $queue = $aPrinterList[$x][6] If $queue = $oldPrinter Then _RemovePrinter($oldPrinter) _AddWindowsPrinterConnection($newPrinter) If $aPrinterList[$x][18] Then _SetDefaultPrinter($newPrinter) EndIf EndIf Next . Edited February 18, 2015 by SmOke_N realtebo 1 Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
YFridman Posted February 18, 2015 Author Share Posted February 18, 2015 Thank you both. Ubound() is exactly "what the doctor ordered." SmOke_N, I tried both boolean and string. both work, yet both return an error. After some additional testing, i found i don't need it at all. If the default printer is removed, the next printer installed becomes default by default (no pun intended) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now