07-25-2011 08:40 AM
Hello,
i would like to know how to sort an 2-D Array or an Multicolumn Listbox. My first column is the the time column. The second column is the Event column and the third column is the Switch column. I know how to sort a 2-d array or an Multicolumn Listbox ascending or descending. But i want to sort it in respect to the actuall time. Attached youu can find an example.
The Time when this was sorted by hand was 16:00 or 4PM.
The time 900 means 9:00 AM.
I'm using labview 2010.
I hope you can understand what i want to do. Maybe someone can give me some help!
If you have any question just tell me
Thanks,
Elvis
07-25-2011 09:59 AM
You said you know how to sort a 2D array or a multicolumn listbox, so what is your specific issue? Is the second picture the result of the sort? Did you write your own code for sorting? Are you perhaps using OpenG's Sort 2D Array functions? Are you having a problem because you're dealing with strings (referring to the ItemNames property for the listbox)?
07-25-2011 10:07 AM - edited 07-25-2011 10:09 AM
By default, strings are sorted alphabetically (e.g. 11 before 5), while you apparently want a numeric sort.
have a look here (check the "true" case in the attached example).
07-25-2011 10:40 AM
yes the second picture is the result of the sort. I know the openG's Sort 2 Array. But I want to sort the Time in respect to the current time. The example should show if the current time is 4 pm the next time in the listbox would be 22:00 or 10pm and after that 1:00. I want to use this for a clock timer! So the common sort vi's don't do this. I need something like an algorithm
07-25-2011 10:43 AM
Did you try the example I linked above?
07-25-2011 10:48 AM
yes i did. If would use this with my listbox. 1:00 would be in the first row and 22:00 or 10PM in the last row. But i wan't that the first row is allways the time which is the closest time to the current time... do you understand my issue?
Thanks for your help!!!
07-25-2011 11:04 AM
So you want the newest time on top? Simply reverse the sort keys.
07-25-2011 11:09 AM - edited 07-25-2011 11:10 AM
@elvis21z wrote:
yes i did. If would use this with my listbox. 1:00 would be in the first row and 22:00 or 10PM in the last row. But i wan't that the first row is allways the time which is the closest time to the current time... do you understand my issue?
I'm not sure if we fully understand what you are saying here. My interpretation is that you did not wire it correctly, because based on your original picture, the sort works:

If that is not what you want, the please provide an exact indication of what the output should be.
07-25-2011 11:30 AM
see picture attached
The sorted listbox should look like the right one (Sorted by time). The current Time is 18:00 (6PM). The next time when something should happen is 22:00 (10PM). That's the reason why 2200 is in the first row.
07-25-2011 11:55 AM