HardCopy Posted July 29, 2005 Share Posted July 29, 2005 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 More sharing options...
seandisanti Posted July 29, 2005 Share Posted July 29, 2005 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.505.009.90but after sorting, i get this6.559.9can this be fixed?Thank youHardcopy<{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 More sharing options...
GaryFrost Posted July 29, 2005 Share Posted July 29, 2005 (edited) 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 July 29, 2005 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 More sharing options...
HardCopy Posted July 29, 2005 Author Share Posted July 29, 2005 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 More sharing options...
GaryFrost Posted July 29, 2005 Share Posted July 29, 2005 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 doneyour sort column has these values:42105How do you think it would sort per your way of doing it? I'll tell you how10245Now is that the correct order? NopeLike 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 More sharing options...
seandisanti Posted July 29, 2005 Share Posted July 29, 2005 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 More sharing options...
HardCopy Posted July 29, 2005 Author Share Posted July 29, 2005 Here's another scenario for you and the reason this is doneyour sort column has these values:42105How do you think it would sort per your way of doing it? I'll tell you how10245Now is that the correct order? NopeGary<{POST_SNAPBACK}>Ah ok GaryI 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 More sharing options...
buzz44 Posted July 30, 2005 Share Posted July 30, 2005 (edited) 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 July 30, 2005 by Burrup qq Link to comment Share on other sites More sharing options...
HardCopy Posted July 30, 2005 Author Share Posted July 30, 2005 Keep in mind that as Gary pointed out,42105Will sort to,10245You can fix this by making sure that each number has the same character length. So for the above you could use,04021005And 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 burrupprefixing prices with spaces where required fixed my problem.still a PITAbut its a workaround.thxHardcopy 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 More sharing options...
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