Jump to content

How to split data in groups


Recommended Posts

$command = @ProgramFilesDir & "\Mozilla Firefox\firefox.exe -new-tab "

$url = "http://fedex.com/Tracking?action=track&language=english&cntry_code=gr&mps=y&tracknumbers="

Run($command & $url&GUICtrlRead($area), "", @SW_MAXIMIZE)

Hi all this is my code above

what i have done is made a GUI that you enter FedEX tracking numbers (12 digits of numbers ONLY comma seperated), then in turn on submit the above script enters the fedex page and displays the PROGRESS of each tracking number (up to 29 they wont allow more) on firefox

NOW what i want to do is if the $area contains say 40 tracking numbers then on submit to open 2 firefox tabs one for the first 29 numbers and one for the rest 11

in a few words if $area contains lots of 12 digit comma seperated numbers to split them in groups of 29 then open a new tab for each 29 records

how can you do this ?

cheers

Edited by asiawatcher
Link to comment
Share on other sites

As long as it isn't against the TOS of the FedEx website then try spliting your list of tracking numbers into multiple arrays and then open a tab using the Send() function. Having said that you should probably use IE so that you can take advantage of the IE functions that are provided by AutoIt. There is a Firefox UDF somewhere on the board but I think an Add-On named MozRepl is required.

Link to comment
Share on other sites

example?

i tried this but i dont know how to complete it

Local $iMax

Local $i

Local $data=GUICtrlRead($box)

; The string in data will be split into an array everywhere , is encountered

Local $arr = StringSplit($data, ",")

If IsArray($arr) Then

Local $iMax = UBound($arr)

;ConsoleWrite("Items in the array: " & $iMax

If $iMax<29 Then

$command = @ProgramFilesDir & "\Mozilla Firefox\firefox.exe -new-tab "

$url = "http://fedex.com/Tracking?action=track&language=greek&cntry_code=gr&mps=y&tracknumbers="

Run($command & $url&GUICtrlRead($box), "", @SW_MAXIMIZE)

ElseIf 29<$iMax Then

For $i = 28 to $iMax - 1

;ConsoleWrite($arr[$i] & @LF)

$command = @ProgramFilesDir & "\Mozilla Firefox\firefox.exe -new-tab "

$url = "http://fedex.com/Tracking?action=track&language=greek&cntry_code=gr&mps=y&tracknumbers="

;For $f = 28

Run($command & $url&$arr[$i-$f], "", @SW_MAXIMIZE)

Next

EndIf

EndIf

Link to comment
Share on other sites

Here is a hack and stab that works for me:

#include <Array.au3>

Global $data = GUICtrlRead($box)

Global $arr = StringSplit($data, ",")

If IsArray($arr) Then
    Global $iMax = $arr[0]

    _ArrayDelete($arr, 0)

    If $iMax <= 29 Then
        new_tab($data)
    ElseIf $iMax > 29 Then
        Global $track_str
        Global $new_arr = $arr

        For $i = 0 To $iMax
            If $i <> 0 And Mod($i, 28) = 0 Then
                $track_str = _ArrayToString($new_arr, ',', 0, 28)
                new_tab($track_str)
                delete_elements($new_arr)
            EndIf
        Next

        $track_str = _ArrayToString($new_arr, ',', 0, $i)
        new_tab($track_str)
    EndIf
EndIf

Func new_tab(Const ByRef $numbers)
    Local Const $command = @ProgramFilesDir & "\Mozilla Firefox\firefox.exe -new-tab"
    Local Const $url = "http://fedex.com/Tracking?action=track&language=greek&cntry_code=gr&mps=y&tracknumbers="
    Run($command & ' ' & $url & $numbers, "", @SW_MAXIMIZE)
EndFunc

Func delete_elements(ByRef $array)
    Local Const $upbound = UBound($array)

    If $upbound >= 29 Then
        For $i = 28 To 0 Step -1
            _ArrayDelete($array, $i)
        Next
    Else
        For $i = $upbound To 0 Step -1
            _ArrayDelete($array, $i)
        Next
    EndIf
EndFunc
Edited by LaCastiglione
Link to comment
Share on other sites

Another skinned cat...

Since it makes more sense to edit your data up front, rather than send garbage across the web, let's assume you have a list that is all 12-digit tracking ID's. That being the case, you don't need much to process it...

;Global $data = GUICtrlRead($box)
Global $data
For $x = 0 to 50
$data &= "123456789A" & StringRight("0" & $x, 2) & ","
Next
$data = StringTrimRight($data, 1)
$data = StringReplace(StringStripWS($data, 8), ",", @CRLF) ; change commas to crlf's
MsgBox(1,"Entire list",$data)
;===============================================================================
While $data
MsgBox(1,"Sending to FedEx",StringLeft($data, 418)) ; 14 * 30 - @CRLF
$data = StringTrimLeft($data, 420) ; 14 * 30
Wend

Everything above the ;============ line is just me simulating your input. The FedEx site says 30 maximum by the way, one per line. I just stuck in a Msgbox() display instead of your actual send to fedex.com

typos

Edited by Spiff59
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...