Jump to content

Array help....


Klexen
 Share

Recommended Posts

I've been working on a program to go through each invoice record on my works site, and if the customer is active then print the invoice page out.

Things I've got working so far

-After searching by name or whatever, you get a list of customer records displayed. The program gathers all the unique links to each customer and adds them to an array.

-Program then navigates to each record checking to see if customer is active

-If customer is active it prompts to print invoice (I wrote a second program to automate the printing process)

-When program has gone through each record on the first page, it goes to the second page (this is where the problem starts)

Gathers the links on second page and adds them to the array again to go through the process... However, after gathering the links on the next page, right before it navigates to them (I know it gets the second pages records and adds them to the array, because I see the new links in an arraydisplay window right before the program crashes), I get this error message..

==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
_IENavigate($oIE, $Unique[$i], 1)
_IENavigate($oIE, ^ ERROR

Here is my code:

$i = 1 ;//Set to one because element 0 in array is the count number of links found
$b = 1 ;//Set to one because element 0 in array is the count number of links found
Do

    $oLinks = _IELinkGetCollection($oIE)
    $iNumLinks = @extended

    Local $avArray[1]
    Local $avArray2[1]

;//Gets the total number of records listed on the page, and stores the links to them in an array
    For $oLink In $oLinks
        $sSplit = StringSplit($oLink.href, "(")
        If $sSplit[1] = "javascript:navigateForm" Then ;//Only takes the links that start with javascript:navigateForm (those are the links for the customers records)
            _ArrayAdd($avArray, $oLink.href)
        EndIf

;//Gets the total number of pages showing, then adds the links to an array
    $sSplit2 = StringSplit($oLink.href, "(")
        If $sSplit2[1] = "javascript:submitAdvLookupForm" Then ;//Only takes the links that are to the next pages
            _ArrayAdd($avArray2, $oLink.href)
        EndIf
    Next

;//Deletes first element in the array, and keeps only the unique links (some of them are listed more than once)
    _ArrayDelete($avArray, 0)
    $Unique = _ArrayUnique($avArray)
    $count = $Unique[0] ;Tells me how many unique records there are so I know when I can stop
    MsgBox(0,"",$count);For checking to make sure it's working
    _ArrayDisplay($Unique);For checking to make sure it's working


    _ArrayDelete($avArray2, 0)
    $Unique2 = _ArrayUnique($avArray2)
    $count2 = $Unique2[0]
;~ MsgBox(0,"",$count2)
;~ _ArrayDisplay($Unique2)


    _IENavigate($oIE, $Unique[$i], 1) ;//Navigates to each link in the array
    _IELoadWait($oIE)

    
    If StringInStr($body, "<TD>Active</TD>") Then ;//Checks to make sure customer is an active customer if so then it prints the customers invoice.
;~      _IEAction($oIE, "print")
    EndIf
    _IEAction($oIE, "back") ;//Navigates back after print, then continues going through each record on page
    _IELoadWait($oIE)
    $i = $i + 1
    If $i = $count and $count2 > 1 Then ;//After it makes it through all the records on the first page, navigates to page 2 and should start process all over until it has gone through each of the pages.

        _IENavigate($oIE, $Unique2[$b], 1)
        _IELoadWait($oIE)

        $b = $b + 1
    EndIf
Until $b = $count2 ;//Should run through this loop until it has gone through all the pages listed.

If someone could help me get it to navigate to the links on the next pages without giving me that array error, you'd be my hero!

Edited by Klexen
Link to comment
Share on other sites

Hi,

i think your problem is the combination of Do..Until loop and $i += 1.

Just change for debugging:

_IENavigate($oIE, $Unique[$i], 1)

to

ConsoleWrite ("i: " & $i & " " & "Arraysize $Unique: " & UBound ($Unique) & @CRLF); add this line to your script and see whats happening

_IENavigate($oIE, $Unique[$i], 1)

Remember that the elements of an array are UBound ($array) - 1 (normally). I guess, that $i is running till $i = UBound ($unique) -> Then your error occurs.

;-))

Stefan

Edited by 99ojo
Link to comment
Share on other sites

Hi,

i think your problem is the combination of Do..Until loop and $i += 1.

Just change for debugging:

_IENavigate($oIE, $Unique[$i], 1)

to

ConsoleWrite ("i: " & $i & " " & "Arraysize $Unique: " & UBound ($Unique) & @CRLF); add this line to your script and see whats happening

_IENavigate($oIE, $Unique[$i], 1)

Remember that the elements of an array are UBound ($array) - 1 (normally). I guess, that $i is running till $i = UBound ($unique) -> Then your error occurs.

;-))

Stefan

This is what is outputed

13 is the amount of links on the first page, 11 is the amount on page 2

i: 1 Arraysize $Unique: 13
i: 2 Arraysize $Unique: 13
i: 3 Arraysize $Unique: 13
i: 4 Arraysize $Unique: 13
i: 5 Arraysize $Unique: 13
i: 6 Arraysize $Unique: 13
i: 7 Arraysize $Unique: 13
i: 8 Arraysize $Unique: 13
i: 9 Arraysize $Unique: 13
i: 10 Arraysize $Unique: 13
i: 11 Arraysize $Unique: 13
i: 12 Arraysize $Unique: 11
C:\Users\Klexen\Documents\invoiceprinter\insurance.au3 (69) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
_IENavigate($oIE, $Unique[$i], 1)
_IENavigate($oIE, ^ ERROR
Edited by Klexen
Link to comment
Share on other sites

Hi,

as you can see is $i bigger then your arraysize -> fault array dimension exceeded, because you try to read an element which doesn't exists.

You have to change your logic of your Do Loop and your increasing of variables and use them, to reference to an array element. Normally you would use a For Loop to reference array elements, e.g:

For $links in $Unique ; use this only, if the first element doesn't hold the number of elements in the array
    _IENavigate($oIE, $links, 1) ;//Navigates to each link in the array
    _IELoadWait($oIE)
Next

or

For $i = 1 To UBound ($Unique) - 1
    _IENavigate($oIE, $Unique[$i], 1) ;//Navigates to each link in the array
    _IELoadWait($oIE)
Next

Hope this helps....

;-))

Stefan

Edited by 99ojo
Link to comment
Share on other sites

Hi,

as you can see is $i bigger then your arraysize -> fault array dimension exceeded, because you try to read an element which doesn't exists.

You have to change your logic of your Do Loop and your increasing of variables and use them, to reference to an array element. Normally you would use a For Loop to reference array elements, e.g:

For $links in $Unique ; use this only, if the first element doesn't hold the number of elements in the array
    _IENavigate($oIE, $links, 1) ;//Navigates to each link in the array
    _IELoadWait($oIE)
Next

or

For $i = 1 To UBound ($Unique) - 1
    _IENavigate($oIE, $Unique[$i], 1) ;//Navigates to each link in the array
    _IELoadWait($oIE)
Next

Hope this helps....

;-))

Stefan

OMG I got it for the most part! The ONLY problem I have now, is that it only shows 5 pages at a time.. When you navigate to the last visible page, it will then show the rest of the pages. Any ideas for getting around that?

Here is the code I got...

$oLinks = _IELinkGetCollection($oIE)
$iNumLinks = @extended

Local $avArray[1]
Local $avArray2[1]

;//Gets the total number of records listed on the page, and stores the links to them in an array
For $oLink In $oLinks
    $sSplit = StringSplit($oLink.href, "(")
    If $sSplit[1] = "javascript:navigateForm" Then ;//Only takes the links that start with javascript:navigateForm (those are the links for the customers records)
        _ArrayAdd($avArray, $oLink.href)
    EndIf

    ;//Gets the total number of pages showing, then adds the links to an array
    $sSplit2 = StringSplit($oLink.href, "(")
    If $sSplit2[1] = "javascript:submitAdvLookupForm" Then ;//Only takes the links that are to the next pages
        _ArrayAdd($avArray2, $oLink.href)
    EndIf
Next

;//Deletes first element in the array, and keeps only the unique links (some of them are listed more than once)
_ArrayDelete($avArray, 0)
$Unique = _ArrayUnique($avArray)
$count = $Unique[0] ;Tells me how many unique records there are so I know when I can stop
MsgBox(0, "", $count);For checking to make sure it's working
_ArrayDisplay($Unique);For checking to make sure it's working


_ArrayDelete($avArray2, 0)
$Unique2 = _ArrayUnique($avArray2)
$count2 = $Unique2[0]
;~ MsgBox(0,"",$count2)
;~ _ArrayDisplay($Unique2)


$b = 1
While $b < $count2
For $i = 1 To UBound ($Unique) - 1
    _IENavigate($oIE, $Unique[$i], 1) ;//Navigates to each link in the array
    _IELoadWait($oIE)

    If StringInStr($body, "<TD>Active</TD>") Then ;//Checks to make sure customer is an active customer if so then it prints the customers invoice.
MsgBox(0,"","Active!")
;~      _IEAction($oIE, "print")
    EndIf
    _IEAction($oIE, "back") ;//Navigates back after print, then continues going through each record on page
    _IELoadWait($oIE)
Next


    _IENavigate($oIE, $Unique2[$b], 1) ;//Navigates to each page in the array
    _IELoadWait($oIE)

$b = $b + 1

WEnd

Thank you for your help man, you're my hero!

Edited by Klexen
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...