Jump to content

Illegal text at the end of statement (one statement per line)


Recommended Posts

I'm getting this error when running the following code.

.... -> "Illegal text at the end of statement (one statement per line).:"

$oLink = $g_listOfLinks[$iIndex]

$oLink = $g_listOfLinks^ ERROR

Everything seems correct to me but I'm pretty new to AutoIt so my syntax or assumptions could be wrong. What am I missing?

#include <IE.au3>
#include <Array.au3>
$g_oIE = _IECreate('http://www.asdf.com')
$g_listOfLinks = _IELinkGetCollection($g_oIE)

Func Main()
    Navigate(10)
EndFunc

Func Navigate($iNavCount)
    For $i = 1 To $iNavCount Step 1
        $iIndex = Random(0, UBound($g_listOfLinks)-1, 1)
        $oLink = $g_listOfLinks[$iIndex]
        Sleep(3000)
    Next
EndFunc

Main()
Edited by graydwarf
Link to comment
Share on other sites

Hi,

The function _IELinkGetCollection returns an object collection not an array, you will have to change the Navigate function logic or convert the collection to an array first.

Edit: Yes, you are correct, take a look at the ParseLinks function in the script below.

#include <IE.au3>


Global $g_oIE = _IECreate('http://www.example.com')
Global $g_listOfLinks


Main()


Func Main()
    ParseLinks() ; get an array of links from the page
    Navigate(10)
EndFunc   ;==>Main

Func Navigate($iNavCount)
    For $i = 1 To $iNavCount Step 1
        $iIndex = Random(0, UBound($g_listOfLinks) - 1, 1)
        $sLink = $g_listOfLinks[$iIndex]
        Sleep(3000)
    Next
EndFunc   ;==>Navigate


; Return values on success: an array of links and sets @extended to link count
; Return values on failure: 0 and sets @error to non-zero
Func ParseLinks()
    Local $aLinks[1000], $n = 0
    Local $oLinks = _IELinkGetCollection($g_oIE) ; get link collection OBJECT
    For $oLink In $oLinks ; loop over link collection items
        $g_listOfLinks[$n] = $oLink.href ; put the url into the array
        $n += 1 ; up the count
    Next
    ReDim $g_listOfLinks[$n] ; correct size
    Return SetError(Not $n, $n, $g_listOfLinks) ; return array
EndFunc   ;==>ParseLinks
Edited by Robjong
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...