Jump to content

Size of 2 dimensional array.


YFridman
 Share

Recommended Posts

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 by YFridman
Link to comment
Share on other sites

  • Moderators

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 by SmOke_N

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...