JohnOne

WEnd array error

7 posts in this topic

#1 ·  Posted (edited)

After a search, I keep seeing answers "Upgrade to newer version of AutoIt" however I believe the error is still present in 3.3.12.0.

I don't believe this belongs in GHAS forum, as there is obviously an undealt with array out of bounds problem in my script, it's just that it could cause confusion when the error is pointing to the wrong place.
 
Here is the func it errors out on, it's not runnable on it's own of course.

Func _LinksActual($Host)
    $iHTMLArrayCurrentIndex = 4
    $aHTMLArray[$iHTMLArrayCurrentIndex] = '4 - Link index<br><br>'
    Local $iHostIndex = _ArraySearch($HostAndLinkArray, $Host, 0, 0, 0, 0, 1, 1)
    If Not @error Then
        Local $FoundHost = $HostAndLinkArray[$iHostIndex][0]
        While $HostAndLinkArray[$iHostIndex][0] = $FoundHost
            $HostSource = BinaryToString(InetRead($HostAndLinkArray[$iHostIndex][1]))
            $Link = _StringBetween($HostSource, 'myButton" href="', '">Click')[0]
            $aHTMLArray[$iHTMLArrayCurrentIndex] &= '<a href="' & $Link & '">' & $Link & '</a><br>'
            $iHostIndex += 1
            Sleep(500)
        WEnd
        ;Wierd error here if no links actual are found
        ;"C:\Documents and Settings\JOHN\Documents\AU3\Projects\WSB.au3" (16) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
        ;WEnd
        ;WEnd^ ERROR
    Else

    EndIf
    _IEBodyWriteHTML($aMainControl[$H_IEOBJ], $aHTMLArray[$iHTMLArrayCurrentIndex])
    Return
EndFunc   ;==>_LinksActual

The only thing I can see which could go wrong here which might cause this, is if the line 

While $HostAndLinkArray[$iHostIndex][0] = $FoundHost

EDIT:

Just for the record, it was that line erroring out, because it was fixed with 

Func _LinksActual($Host)
    $iHTMLArrayCurrentIndex = 4
    $aHTMLArray[$iHTMLArrayCurrentIndex] = '4 - Link index<br><br>'
    Local $iHostIndex = _ArraySearch($HostAndLinkArray, $Host, 0, 0, 0, 0, 1, 1)
    If Not @error Then
        Local $FoundHost = $HostAndLinkArray[$iHostIndex][0]
        While $iHostIndex < UBound($HostAndLinkArray) And $HostAndLinkArray[$iHostIndex][0] = $FoundHost
            $HostSource = BinaryToString(InetRead($HostAndLinkArray[$iHostIndex][1]))
            $Link = _StringBetween($HostSource, 'myButton" href="', '">Click')[0]
            $aHTMLArray[$iHTMLArrayCurrentIndex] &= '<a href="' & $Link & '">' & $Link & '</a><br>'
            $iHostIndex += 1
            Sleep(500)
        WEnd
    Else
        $iHTMLArrayCurrentIndex -= 1
        Return
    EndIf
    _IEBodyWriteHTML($aMainControl[$H_IEOBJ], $aHTMLArray[$iHTMLArrayCurrentIndex])
    Return
EndFunc   ;==>_LinksActual
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I can't help wondering if this is perhaps a bit of a trade-off. The code terminates abruptly before ever reaching WEnd because of an out of bounds array error. Interpreting events like this may not be practical beyond a certain point. It could simply be a knock-on effect. Whether this is the case here, I really don't know. I would rather the interpreter threw out all the errors it encounters, and if fixing one of them fixes them all, I'm more than happy.

Edited by czardas

Share this post


Link to post
Share on other sites

So the concerne is in the line where the error show up.

The while line should be better as the error is really when referencing a wrong entry

right ?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

It would make it easier to debug the code, so I would say yes.

Edited by czardas

Share this post


Link to post
Share on other sites

So the concerne is in the line where the error show up.

The while line should be better as the error is really when referencing a wrong entry

right ?

Yes exactly that. In a busier while loop, and if you don't know why it occurs, could be confusing.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
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