SKIP 1
ELSE && Just came from DESC order using SKIP -1
lcPrevOrder = "A"
SKIP -1 && Go back to the last "D" that was just processed.
SET ORDER TO ixASC && "D" is now the last in the group of Ds.
SKIP -1 && Move to the first "A" of next group.
SKIP 1
ENDIF
ELSE
SET ORDER TO ixDESC
SKIP -1
ENDIF
ENDDO
I'm sure that there will have to be some other checking to make sure that we eventually get to EOF(), that we don't get stuck at BOF(), and that nothing is done twice but the idea is that if I hit a D while in ASCENDING order then all of the rest of the Ds will be below it in ascending order but, staying on the same record, if I then switch to descending order all of the Ds will now be above it. I can then process each of those in turn with and then issue a SKIP -1 until I hit the previous "A" that was already processed. When I change ORDER back to Ascending the "D" that was on the top of the group will now be on the bottom of the Group so a single SKIP -1 will put me into the next Group of "A"s.
Like I said, I haven't tried this yet and there definitely needs to be extra code to handle EOF() and BOF() but I this might be the solutions with the fewest steps.
Thanks again and wish me luck.
Ed
>Edmond,
>
>Although it is hacking to the max, maybe this can be of help:
>
>contents of udftest.prg:
>LPARAMETERS cDA
>
>IF TYPE('gcDA')='U'
> PUBLIC gcDA
> gcDA=cDa
>ENDIF
>IF TYPE('gnGroup')='U'
> PUBLIC gnGroup
> gnGroup=0
>ENDIF
>
>IF TYPE('gnCounter')='U'
> PUBLIC gnCounter
> gnCounter=0
>ENDIF
>
>
>
>IF gcDA<>cDa
> gcDa=cDa
> gnCounter=0
> gnGroup=gnGroup+1
>ENDIF
>
>gnCounter=gnCounter+1
>
>LOCAL dlcRetVal
>dlcRetVal=STR(gnGroup,5)+IIF(cDa='A',STR(gnCounter,5),STR(10000-gnCounter,5))
>
>
>RETURN dlcRetVal
>
>
>To use it, try this from the command window:
>
>create table test (cKey C(5), cDA C(1))
>insert into test (ckey, cda) values ("10001",'A')
>insert into test (ckey, cda) values ("10002",'A')
>insert into test (ckey, cda) values ("10003",'A')
>insert into test (ckey, cda) values ("10004",'A')
>insert into test (ckey, cda) values ("10005",'D')
>insert into test (ckey, cda) values ("10006",'D')
>insert into test (ckey, cda) values ("10007",'D')
>insert into test (ckey, cda) values ("10008",'D')
>insert into test (ckey, cda) values ("10009",'D')
>insert into test (ckey, cda) values ("10010",'A')
>insert into test (ckey, cda) values ("10011",'A')
>insert into test (ckey, cda) values ("10012",'A')
>insert into test (ckey, cda) values ("10013",'D')
>insert into test (ckey, cda) values ("10014",'D')
>select udftest(cda),* from test order by 1
>RELEASE gcDA,gnGroup,gnCounter
>
>hth,