graydwarf Posted January 14, 2012 Share Posted January 14, 2012 (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 January 14, 2012 by graydwarf Link to comment Share on other sites More sharing options...
graydwarf Posted January 14, 2012 Author Share Posted January 14, 2012 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. Link to comment Share on other sites More sharing options...
Robjong Posted January 14, 2012 Share Posted January 14, 2012 (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 January 14, 2012 by Robjong graydwarf 1 Link to comment Share on other sites More sharing options...
graydwarf Posted January 14, 2012 Author Share Posted January 14, 2012 Thanks Robjong! I'm back on track now. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now