Sign in to follow this  
Followers 0
graydwarf

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

4 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



Alright, looks like this is a collection vs array problem. I need to look into how to access a specific object in the collection or perhaps loop through using a for/next.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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
1 person likes this

Share this post


Link to post
Share on other sites

Thanks Robjong! I'm back on track now.

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
Sign in to follow this  
Followers 0