Sign in to follow this  
Followers 0
computergroove

My array is getting written over instead of added to

4 posts in this topic

#1 ·  Posted (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 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

Share this post


Link to post
Share on other sites



#2 ·  Posted (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]
EndIf

Br,

UEZ

Edited 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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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

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