Modify

Opened 17 years ago

Closed 17 years ago

Last modified 17 years ago

#81 closed Bug (No Bug)

_ArraySort output bad if first chararacter of alphanumeric string is numeric.

Reported by: autoitfan Owned by:
Milestone: Component: AutoIt
Version: 3.2.10.0 Severity:
Keywords: Cc:

Description

;Following sample program demonstrates problem.

#include <array.au3>

Dim $array[10], $cnt

$array[1] = "cba"

$array[2] = "1ba"

$array[3] = "abc"

$array[0] = 3

MSGBOX(0,"BEFORE SORT", $array[0]&" "&$array[1]&" "&$array[2]&" "&$array[3])

;MSGBOX "BEFORE SORT" displays: 3 cba 1ba abc

_ArraySort( $array)

MSGBOX(0,"AFTER SORT", $array[0]&" "&$array[1]&" "&$array[2]&" "&$array[3])

;MSGBOX "AFTER SORT" displays: 0 abc 0 cba

;Should be: 3 1ba abc cba

Exit

Attachments (0)

Change History (2)

comment:1 follow-up: Changed 17 years ago by Valik

  • Resolution set to nobug
  • Status changed from new to closed

There's no bug here. First of all, you're using an array that's way bigger than you need. That means with the default sort direction, all those empty values are going to be first (Which explains why you get no output). Correcting the array size to be 4, your expected output is still wrong. Again, the default option for _ArraySort() is to start at index 0. What you expect is to star at index 1.

This code does what you want, mostly because it's written correctly.

#include <Array.au3>

Local $array[4] = [ 3, "cba", "1ba", "abc" ]

MSGBOX(0,"BEFORE SORT", $array[0]&" "&$array[1]&" "&$array[2]&" "&$array[3])

;MSGBOX "BEFORE SORT" displays: 3 cba 1ba abc

_ArraySort( $array, 0, 1)

MSGBOX(0,"AFTER SORT", $array[0]&" "&$array[1]&" "&$array[2]&" "&$array[3])

;MSGBOX "AFTER SORT" displays: 0 abc 0 cba

;Should be: 3 1ba abc cba

Exit

comment:2 in reply to: ↑ 1 Changed 17 years ago by ptheckler@…

Thank you for supplying the key bit of information about the default starting
$i_base being zero (0). This was the only time I had used _ArraySort and since
array[0] has traditionally been used to indicate the number of active array
elements, it didn't occur to me that the $i_base default might be zero.

The reason the array was defined with ten elements was because they were being
initialized from an INI file subheading list containing an indeterminate number
of entries up to a MAX of 9. After correcting my $ArraySort statement as per your
information, I resolved this with DIM $array[1] and used _ArrayAdd to expand the array as INI entries were inputted.

By the way, in the actual script where I first ran into this problem, this logic had worked fine for weeks until an INI entry beginning with a numeric came along.
And, in testing, I found that substituting an alpha character ahead of each entry,
(i.e., zcba, z1bc, zabc) worked fine, but of course this was not a resolution.
It is true that $array[0] was beening reset to zero across _ArraySort, but since
it was set to the correct value by a subsequent statement in the script, this problem didn't manifest itself.

Thank you again. I had asked about this on a forum, but the only answer I got was
not helpful. Sorry for the false alarm bug report. Paul Heckler

Replying to Valik:

There's no bug here. First of all, you're using an array that's way bigger than you need. That means with the default sort direction, all those empty values are going to be first (Which explains why you get no output). Correcting the array size to be 4, your expected output is still wrong. Again, the default option for _ArraySort() is to start at index 0. What you expect is to star at index 1.

This code does what you want, mostly because it's written correctly.

#include <Array.au3>

Local $array[4] = [ 3, "cba", "1ba", "abc" ]

MSGBOX(0,"BEFORE SORT", $array[0]&" "&$array[1]&" "&$array[2]&" "&$array[3])

;MSGBOX "BEFORE SORT" displays: 3 cba 1ba abc

_ArraySort( $array, 0, 1)

MSGBOX(0,"AFTER SORT", $array[0]&" "&$array[1]&" "&$array[2]&" "&$array[3])

;MSGBOX "AFTER SORT" displays: 0 abc 0 cba

;Should be: 3 1ba abc cba

Exit

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.