WhiteCrow Posted October 20, 2006 Posted October 20, 2006 (edited) My script errors out: while i think it should work 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 expandcollapse popup#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 I cant figure this out yet, thanks for any help in advance. Edited October 20, 2006 by WhiteCrow
GaryFrost Posted October 20, 2006 Posted October 20, 2006 (edited) Probably better ways to do this, just modified yours a bit to make it work. Something to think about would be IniReadSection maybe expandcollapse popup#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 October 20, 2006 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.
WhiteCrow Posted October 21, 2006 Author Posted October 21, 2006 (edited) Your sollution works without any problems, thanks for your answer! You are kindoff my hero PS i always tought ReDim destroyed the array (set it to null) This sets it to a new light, thanks you. Edited October 21, 2006 by WhiteCrow
GaryFrost Posted October 21, 2006 Posted October 21, 2006 Your sollution works without any problems, thanks for your answer!You are kindoff my hero PSi 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.
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