Sanja Posted May 5, 2018 Posted May 5, 2018 Dear forum, I want to get all the links from a website via _IELinkGetCollection and store them imediatley in an array. As the title states I have a problem with creating an array in a For - In - Next loop. I know, I know the helpfile says that arrays in an For-In-Next loop are readonly. I thought that aplies only to the array I am reading - not the one I am writing in, if they are different arrays. Anyway, I tried the following: #include <AutoItConstants.au3> #include <IE.au3> #include <Array.au3> Local $oIEBasic = _IE_Example ("basic") Local $aLinkPaths Local $oAllWebsiteLinks = _IELinkGetCollection($oIEBAsic) Local $i = 0 For $oSingleLink In $oAllWebsiteLinks $i = $i + 1 $aLinkPaths [$i] = _IEPropertyGet ($oSingleLink, "innertext") Next _IEQuit ($oIEBasic) Exit Which leads to the following error message: "Line 29 $aLinkPaths [$i] = _IEPropertyGet ($oSingleLink, "innertext") $aLinkPaths ^ ERROR Error: Subscript used on non-accessible variable." Then I tried a For-To loop, which just freezes the script so I have to end it with the task manager and also does not show any array. To be honest I dont even know if I am allowed to treat a collection object as an array... #include <AutoItConstants.au3> #include <IE.au3> #include <Array.au3> Local $oIEBasic = _IE_Example ("basic") Local $aLinkPaths Local $oAllWebsiteLinks = _IELinkGetCollection($oIEBAsic) For $oAllWebsiteLinks [0] To UBound ($oAllWebsiteLinks) - 1 $aLinkPaths [$i] = _IEPropertyGet ($oSingleLink, "innertext") Next _ArrayDisplay ($aLinkPaths) _IEQuit ($oIEBasic) Exit I found a solution with the _ArrayAdd function. #include <AutoItConstants.au3> #include <IE.au3> #include <Array.au3> Local $oIEBasic = _IE_Example ("basic") Local $aLinkPaths [0] Local $sLinkInnerText Local $oAllWebsiteLinks = _IELinkGetCollection($oIEBAsic) For $oSingleLink In $oAllWebsiteLinks $sLinkInnerText = _IEPropertyGet ($oSingleLink, "innertext") _ArrayAdd ( $aLinkPaths, $sLinkInnerText) Next _ArrayDisplay ($aLinkPaths) _IEQuit ($oIEBasic) Exit So I already have a solution for my problem which works just fine. It seems that I am allowed and fill an array in a For-In-Next loop by just adding values to an existing array. I am just curious if there is an "easier" way to do what I wanted with a solution which looks more like what I tried to first two times. Thank you in advance.
jchd Posted May 5, 2018 Posted May 5, 2018 Try this: #include <AutoItConstants.au3> #include <IE.au3> #include <Array.au3> Local $oIEBasic = _IE_Example("basic") Local $oAllWebsiteLinks = _IELinkGetCollection($oIEBAsic) Local $aLinkPaths[@extended] Local $i = 0 For $oSingleLink In $oAllWebsiteLinks $aLinkPaths[$i] = _IEPropertyGet($oSingleLink, "innertext") $i = $i + 1 Next _IEQuit ($oIEBasic) _ArrayDisplay($aLinkPaths) Help on _IELinkGetCollection() says that @extended returns the number of links in the collection. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
Sanja Posted May 6, 2018 Author Posted May 6, 2018 Ah right, I didnt think of alle the @... functions. Now it works just as intended. Thank you very much, jchd!
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