Re: Sorting and listviews
- Posted by irvm at ellijay.com Jul 13, 2001
- 375 views
On Friday 13 July 2001 05:25, Tony Steward wrote: > Secondly has anyone written a sort routine they would like to share. My > problem is as follows: > N1-1-1 > N1-1-10 > N1-1-2 > N1-1-3 > > This is a typical numbering system used in master key systems and I would > rather have them display in a listview as follows: > N1-1-1 > N1-1-2 > N1-1-3 > N1-1-10 > > The default sort routine looks very unprofessional, and as I use the lists > to set the order of reports it is even more un professional. > > Thanks > Tony Steward Here's a way that works by converting the array into numbers, sorting, then converting back to strings for display. If you've got a mix of numeric and non-numerics, ("N1-1-10A") then it won't without some serious modifications. include sort.e include get.e include strtok.e sequence s, sn object v s = {"N1-1-1","N1-1-10","N1-1-3","N1-1-2"} sn = s -- save into temporary new array for i = 1 to length(sn) do sn[i] = parse(sn[i],'-') -- parse into numbers v = value(sn[i][2]) -- convert to numeric sn[i][2] = v[2] v = value(sn[i][3]) sn[i][3] = v[2] ? sn[i] end for puts(1,"Sorted\n") sn = sort(sn) for i = 1 to length(sn) do -- change 'em back to strings printf(1,"%s-%d-%d\n",{sn[i][1],sn[i][2],sn[i][3]}) end for