Sign in to follow this  
Followers 0
autoitfan

Having a problem with _ArraySort

4 posts in this topic

I have an array containing song titles

I tried to sort with _ArraySort. One of the

titles is 12th Street Rag which appears

as 0 (a numeric zero) in the sorted output.

Numbers within a title beginning with an

alpha character don't appear to cause

any problems.

I could not find a documented restriction to

the effect that alphanumeric array content

must begin with an alpha character.

When I change the title to "Twelfth Street

Rag", _ArraySort generates perfectly

sorted output, but control of the titles

is not mine, so this is not an acceptable

bypass.

Is this a bug or just the way it works?

And, is there another way to sort an

array?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I have an array containing song titles

I tried to sort with _ArraySort. One of the

titles is 12th Street Rag which appears

as 0 (a numeric zero) in the sorted output.

Numbers within a title beginning with an

alpha character don't appear to cause

any problems.

I could not find a documented restriction to

the effect that alphanumeric array content

must begin with an alpha character.

When I change the title to "Twelfth Street

Rag", _ArraySort generates perfectly

sorted output, but control of the titles

is not mine, so this is not an acceptable

bypass.

Is this a bug or just the way it works?

And, is there another way to sort an

array?

How are you building the array and how are you calling _ArraySort()? You could be starting the sort on the wrong element. It's happened to me more than once. Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

How are you building the array and how are you calling _ArraySort()? You could be starting the sort on the wrong element. It's happened to me more than once.

Thank you for your response. The unsorted song titles are

contained in a simple flat file in the order they were added

to the file. They are simply read into an one dim array, one

title per element. Keep in mind that the sorted output is

correct except for the one title (12th Street Rag) that begins

with a numeric, the sorted output is correct except for that

single title which appears as a zero (0), and that simply

changing the "12" to "Twelf" results in sort output that is

perfect in every respect.

Paul

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thank you for your response. The unsorted song titles are

contained in a simple flat file in the order they were added

to the file. They are simply read into an one dim array, one

title per element. Keep in mind that the sorted output is

correct except for the one title (12th Street Rag) that begins

with a numeric, the sorted output is correct except for that

single title which appears as a zero (0), and that simply

changing the "12" to "Twelf" results in sort output that is

perfect in every respect.

Paul

That didn't tell me exactly what I needed so I gambled and built the array with _FileReadToArray(). It works for me so I suspect the problem is in the way you called _ArraySort() You didn't check the parameters nor did you check to see if $Array[0] contained data from your file or the number of elements in the array. In the case of _FileReadTo Array it contains the number of elements. _Array Sort has a parameter for the sort start position which defaults to 0 so the size of your array also was sorted. and that would have place 12th Street Rag in position 0. You then called a loop starting at 1 "Ooooopps, Im missing a file!!". NOT. Change your _ArraySort() cal to the following and all will be well with the world again.

_ArraySort($array, 0, 1)

EDIT: Here is my complete test code if it helps

#include <file.au3>
#include <Array.au3>
$iFile = @desktopDir & "\test.txt"
$Array = ""
 _FileReadToArray($iFile, $array)
 _ArraySort($array, 0, 1)
For $I = 1 to Ubound($array) -1
   MsgBox(0, "Test", $Array[$I])
Next
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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