Sign in to follow this  
Followers 0
WhiteCrow

Arraysorting problem

4 posts in this topic

#1 ·  Posted (edited)

My script errors out: while i think it should work :lmao:

What it sorts(or atleast im trying to)

artists.dat is made like this:

[indexnumber 1]

artist=Blabla

track=Songname BlaBla

url=qweoiqhja some url php code

time=09:99

what i try to do is

first split the $data array in 4 seperate Arrays $artist[0] (thats artist name), $artist[1] (thats old indexnumber), $track, $url, $time

then _arraysort $artist

then rebuild the file:

$artist[0] <now sorted

then refind songname, url, time with precious indexnumber stored in $artist[1]

But it gives a error line 564 from the Include Array.au3

#include <Array.au3>
#include <File.au3>

Dim $data

_FileReadToArray ("artists.dat", $data)
$data_end=Ubound($data)-1

$x=0

Dim $artist[3000][2]
Dim $url[3000]
Dim $track[3000]
Dim $index[3000]
Dim $time[3000]
Dim $new[1]
$sortcount=0

For $iPos = 0 To $data_end
    $Stringpos=StringInStr ($data[$iPos], "[Indexnumber" )

    If $StringPos <> 0 Then
        $x+=1
        $index[$x]=$x
        $iPos+=1
        $artist[$x][0]=Stringtrimleft($data[$ipos], 7)
        $artist[$x][1]=$x
        $iPos+=1
        $track[$x]=Stringtrimleft($data[$ipos], 6)
        $iPos+=1
        $url[$x]=Stringtrimleft($data[$ipos], 4)
        $iPos+=1
        $time[$x]=Stringtrimleft($data[$ipos], 5)
        EndIf
    Next
    
_ArraySort($artist)

$x=0
$data_end=Ubound($index)-1

For $x = 1 To $data_end
    _ArrayAdd($new, "[Indexnumber " & $x "]")
    _ArrayAdd($new, "artist=" & $artist[$x][0])
    _ArrayAdd($new, "track=" & $track[$artist[$x][1]])
    _ArrayAdd($new, "url="& $url[$artist[$x][1]])
    _ArrayAdd($new, "time="& $time[$artist[$x][1]])
    $sortcount+=1
Next

$data=""

MsgBox(0, "Sorted!", "Total number of clips resorted: " & $sortcount)

_FileWriteFromArray("artist_sorted.dat", $new)

I thought is was a smart way to re-index, while keeping and re-using the old index :ph34r:

I cant figure this out yet, thanks for any help in advance.

Edited by WhiteCrow

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Probably better ways to do this, just modified yours a bit to make it work.

Something to think about would be IniReadSection maybe

#include <Array.au3>
#include <File.au3>

Dim $data

_FileReadToArray(@ScriptDir & "\artists.dat", $data)
$data_end = UBound($data) - 1

$x = 1

Dim $artist[1][2]
Dim $url[1]
Dim $track[1]
Dim $index[1]
Dim $time[1]
Dim $new[1]
$sortcount = 0
$artist[0][0] = 0
For $iPos = 0 To $data_end
    $Stringpos = StringInStr($data[$iPos], "[Indexnumber")

    If $Stringpos <> 0 Then
        ReDim $artist[$x + 1][2]
        ReDim $index[$x + 1]
        ReDim $track[$x + 1]
        ReDim $url[$x + 1]
        ReDim $time[$x + 1]
        $index[$x] = $x
        $iPos += 1
        $artist[$x][0] = StringTrimLeft($data[$iPos], 7)
        $artist[$x][1] = $x
        $iPos += 1
        $track[$x] = StringTrimLeft($data[$iPos], 6)
        $iPos += 1
        $url[$x] = StringTrimLeft($data[$iPos], 4)
        $iPos += 1
        $time[$x] = StringTrimLeft($data[$iPos], 5)
        $x += 1
    EndIf
Next

_ArraySort($artist, 0, 1, 0, 2)

$x = 0
$data_end = UBound($index) - 1

For $x = 1 To $data_end
    _ArrayAdd($new, "[Indexnumber " & $x & "]")
    _ArrayAdd($new, "artist=" & $artist[$x][0])
    _ArrayAdd($new, "track=" & $track[$artist[$x][1]])
    _ArrayAdd($new, "url=" & $url[$artist[$x][1]])
    _ArrayAdd($new, "time=" & $time[$artist[$x][1]])
    $sortcount += 1
Next

$data = ""

MsgBox(0, "Sorted!", "Total number of clips resorted: " & $sortcount)

_FileWriteFromArray("artist_sorted.dat", $new)
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Your sollution works without any problems, thanks for your answer!

You are kindoff my hero :lmao:

PS

i always tought ReDim destroyed the array (set it to null)

This sets it to a new light, thanks you.

Edited by WhiteCrow

Share this post


Link to post
Share on other sites

Your sollution works without any problems, thanks for your answer!

You are kindoff my hero :lmao:

PS

i always tought ReDim destroyed the array (set it to null)

This sets it to a new light, thanks you.

The ReDim keyword is similar to Dim, except that ReDim preserves the values in the array instead of removing the values while resizing an array.


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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