Re: Sorting and listviews

new topic     » goto parent     » topic index » view thread      » older message » newer message

On 13 Jul 2001, at 22:17, Igor Kachan wrote:

> 
> Hi Tony,
> 
> > 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.
> 
> 
> The possible solution is :
> 
> N1-1-01
> N1-1-10
> N1-1-02
> N1-1-03
> 
> Then standard RDS include sort.e  
> and sort() works as you wish, i.e.
> 
> N1-1-01
> N1-1-02
> N1-1-03
> N1-1-10

Great minds think alike, eh, Igor? I was just coding that solution too! The 
code to do this would be sort of like:


-- Sort a list
-- Kat
-- July 13, 2001

with trace
include sort.e
include get.e
include strtok.e - you might haveto make parse() and deparse() global

atom key
sequence list, parsedlist
-- set list to something, so we can sort it
list = {
"N1-1-1",
"N1-1-10",
"N1-1-2",
"N1-1-3",
"N3-1-10",
"N3-4-2",
"N21-5-9"
}

puts(1,"starting with:\n")
for loop = 1 to length(list) do
  puts(1,list[loop]&"\n")
end for
puts(1,"\n\n")

for loop = 1 to length(list) do
  parsedlist = parse(list[loop],'-')
  for loop2 = 1 to length(parsedlist) do
    while length(parsedlist[loop2]) < 5 do -- 5 is a rather random number
      parsedlist[loop2] = "0" & parsedlist[loop2]
    end while
  end for
  list[loop] = deparse(parsedlist,'-')
end for

list = sort(list)

for loop = 1 to length(list) do
  parsedlist = parse(list[loop],'-')
  for loop2 = 1 to length(parsedlist) do
      while equal('0',parsedlist[loop2][1]) do
        parsedlist[loop2] = parsedlist[loop2][2..length(parsedlist[loop2])]
      end while
    end for
  list[loop] = deparse(parsedlist,'-')
end for

for loop = 1 to length(list) do
  puts(1,list[loop]&"\n")
end for

puts(1,"\n\nall done, press something to close out\n\n")
key = wait_key()

Kat

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu