Jump to content

_GUICtrlListViewSort - Bug or Feature?


Recommended Posts

Dont know if any one else had encountered this or can suggest a temp workaround.

im using _GUICtrlListViewSort . to sort prices in a listview control. using latest beta version.

When the listviewitems are initially populated from a TABBED CSV File, all price masking is correct.

However on sorting, by clicking column header, the trailing zeros are missing on the prices :

ie before sorting everything is fine:

6.50

5.00

9.90

but after sorting, i get this

6.5

5

9.9

can this be fixed?

Thank you

Hardcopy

Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Link to comment
Share on other sites

Dont know if any one else had encountered this or can suggest a temp workaround.

im using _GUICtrlListViewSort . to sort prices in a listview control. using latest beta version.

When the listviewitems are initially populated from a TABBED CSV File, all price masking is correct.

However on sorting, by clicking column header, the trailing zeros are missing on the prices :

ie  before sorting everything is fine:

6.50

5.00

9.90

but after sorting, i get this

6.5

5

9.9

can this be fixed?

Thank you

Hardcopy

<{POST_SNAPBACK}>

you may want to explicitly typecast your values, you can use Round(Value, Decimal Places) to make sure your values stay as numbers. I think that may do it for you, but can't test without code
Link to comment
Share on other sites

type cast won't help in this case, if you want to keep your zero's you might have to come up with your own sort.

the listview treats your numbers as strings i believe so they will stay, but once it is passed to the sort they are converted to numbers if they are float or int, being this is a c based scripting language, if my memory serves me right, been a while since I've used c/c++ it will take the zero's off the number, therefore you'll have to format the numbers the way you want them to appear when put back in the listview.

@cameronsdad

here's an example of type-casting the value that would come from a listview which is done for the user in the sort routine

MsgBox(0,"test",Number("3.50"))

Gary

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.

 

Link to comment
Share on other sites

you may want to explicitly typecast your values, you can use Round(Value, Decimal Places) to make sure your values stay as numbers.  I think that may do it for you, but can't test without code

<{POST_SNAPBACK}>

round is not the answer, in fact its a problem in itself. (maybe my syntax is wrong but....)

$val = round("2.50",2)
MsgBox(4096,"",$val)

this loses the trailing zero too.!!!!

I could use the stringformat command to mask currency.

But the problem in my opinion is the UDF itself. It should return sorted, the values given and not alter them in anyway. It should not be necessary to parse/reformat the data again every time its sorted.

Hardcopy

Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Link to comment
Share on other sites

round is not the answer, in fact its a problem in itself. (maybe my syntax is wrong but....)

$val = round("2.50",2)
MsgBox(4096,"",$val)

this loses the trailing zero too.!!!!

I could use the stringformat command to mask currency.

But the problem in my opinion is the UDF itself.  It should return sorted, the values given and not alter them in anyway. It should not be necessary to parse/reformat the data again every time its sorted.

Hardcopy

<{POST_SNAPBACK}>

Here's another scenario for you and the reason this is done

your sort column has these values:

4

2

10

5

How do you think it would sort per your way of doing it? I'll tell you how

10

2

4

5

Now is that the correct order? Nope

Like I said if you want your zero's kept in you'll have to write your own custom sort routine. This is a generic sort.

The above scenario is in the bug fixed part of the forum.

Gary

SciTE for AutoItDirections for Submitting Standard UDFs

 

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

 

Link to comment
Share on other sites

round is not the answer, in fact its a problem in itself. (maybe my syntax is wrong but....)

$val = round("2.50",2)
MsgBox(4096,"",$val)

this loses the trailing zero too.!!!!

I could use the stringformat command to mask currency.

But the problem in my opinion is the UDF itself.  It should return sorted, the values given and not alter them in anyway. It should not be necessary to parse/reformat the data again every time its sorted.

Hardcopy

<{POST_SNAPBACK}>

It's a necessary trade off created by having all of the variables stored as variants for ease of use and flexibility. If you were required to declare types at creation like alot of other languages, people would then have to handle alot of their own conversions and typecasting themselves just like those other languages that alot of us have cut down on having to use thanks to autoit. Personally i'd rather have to add a conditional statement that adds a '0' to the end of the string before it's displayed if there aren't enough places after the decimal than sacrifice the 'on the fly' variable creation and use allowed by the variant data type
Link to comment
Share on other sites

Here's another scenario for you and the reason this is done

your sort column has these values:

4

2

10

5

How do you think it would sort per your way of doing it? I'll tell you how

10

2

4

5

Now is that the correct order? Nope

Gary

<{POST_SNAPBACK}>

Ah ok Gary

I see what you mean...hmmm %$^&$#

Looks like i got a few more lines of code to write.

Thx for the prompt replies fellas , i appreciate it.

Hardcopy

Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Link to comment
Share on other sites

Keep in mind that as Gary pointed out,

4

2

10

5

Will sort to,

10

2

4

5

You can fix this by making sure that each number has the same character length. So for the above you could use,

04

02

10

05

And it will sort correctly, or alternatively you can just use white space if you want zero's.

For this to work you will have to find out the largest string length in the column your sorting, then create a routine that will add more length (zero/white space or w/e) to the other items in the column, so they all have the same length.

Edited by Burrup

qq

Link to comment
Share on other sites

Keep in mind that as Gary pointed out,

4

2

10

5

Will sort to,

10

2

4

5

You can fix this by making sure that each number has the same character length. So for the above you could use,

04

02

10

05

And it will sort correctly, or alternatively you can just use white space if you want zero's.

For this to work you will have to find out the largest string length in the column your sorting, then create a routine that will add more length (zero/white space or w/e) to the other items in the column, so they all have the same length.

<{POST_SNAPBACK}>

Thx burrup

prefixing prices with spaces where required fixed my problem.

still a PITA

but its a workaround.

thx

Hardcopy

Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

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...