computergroove Posted December 11, 2014 Posted December 11, 2014 (edited) My code gets the source code of a website and returns a unique set of values from each page it scans. In the following code I add a value to my array in a loop with _ArrayAdd. When the loop starts the second $j loop and beyond, the data in $Array gets written over with the new loops data. I want it to add the value to the bottom of the existing array. There are currently 19 pages in the website with 20 unique links per page and 6 on the last page so my array should be around 366 rows long (18 pages * 20 links per page + 6). Its 6 rows long at the end of my script. If I manually step through each loop, $Array is 20 rows long until I reach the last loop. Global $Array[0] For $k = 1 To 19 For $j = 1 To 20 Local $HTML = _INetGetSource($url) $1 = StringInStr($HTML, "/expose/", 0, $j) $2 = StringTrimLeft($HTML, $1) $3 = StringReplace($2, '"', ";;") $4 = StringSplit($3, ";;", 1) $5 = $4[1] $6 = StringMid($5, 8, 8) If $6 >= 1 Then _ArrayAdd($Array, $6);<-- Here is where the array is adding to the existing array EndIf Next $url = "www.examplewebpage/Page" & $k & ".html" Next Edited December 11, 2014 by computergroove Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html
UEZ Posted December 11, 2014 Posted December 11, 2014 (edited) _ArrayAdd might be slow on 19 * 20 loops: Try this (not tested):Global $Array[19 * 20], $z = 0 For $k = 1 To 19 For $j = 1 To 20 Local $HTML = _INetGetSource($url) $1 = StringInStr($HTML, "/expose/", 0, $j) $2 = StringTrimLeft($HTML, $1) $3 = StringReplace($2, '"', ";;") $4 = StringSplit($3, ";;", 1) $5 = $4[1] $6 = StringMid($5, 8, 8) If $6 >= 1 Then $Array[$z] = $6 ;<-- Here is where the array is adding to the existing array $z += 1 EndIf Next $url = "www.examplewebpage/Page" & $k & ".html" Next If Not $z Then MsgBox(0, "Info", "Nothing added to the array") Else ReDim $Array[$z] EndIfBr,UEZ Edited December 11, 2014 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Moderators Melba23 Posted December 11, 2014 Moderators Posted December 11, 2014 computergroove,I have reduced your code to a minimum and it adds the elements without problem: #include <Array.au3> Global $Array[0] For $k = 1 To 19 For $j = 1 To 20 $6 = $k & " - " & $j If $6 >= 1 Then _ArrayAdd($Array, $6);<-- Here is where the array is adding to the existing array EndIf Next Next _ArrayDisplay($Array, "", Default, 8)I note that $6 is a string and you are comparing it to a numeric value before adding it to the array. When you do this AutoIt forces both sides of the comparison to number format - and a string return 0 when this happens. I rather think that this is the root of your problem - try adding a letter as the first character of the $6 = assignment and see what happens. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Solution computergroove Posted December 12, 2014 Author Solution Posted December 12, 2014 For $k = 2 To 20 GetNumberedLinks() _ArrayConcatenate($FinalArray,$Array) $url = "www.examplewebpage/Page" & $k & ".html" $HTML = _INetGetSource($url) Next Func GetNumberedLinks() $HTML = _INetGetSource($url) $j = 1 Do $1 = StringInStr($HTML, "/expose/", 0, $j) $2 = StringTrimLeft($HTML, $1) $3 = StringReplace($2, '"', ";;") $4 = StringSplit($3, ";;", 1) $5 = $4[1] $6 = StringMid($5, 8, 8) If $6 >= 1 Then;Needed to add this if statement because I was getting extra characters at the end of the finalarray _ArrayAdd($Array,$6,1) EndIf $j += 1 Until $1 = 0;Stop loop when there are no more instances of "/expose/" $Array = _ArrayUnique($Array,0,0,0,0) EndFunc I got it to work using this. Changing the variable labels to letters produced the same result. Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html
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