Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
INDEX ON....IIF(x,'ASCENDING','DESCENDING')
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00350533
Message ID:
00351379
Views:
22
Frank,

Just looking at the code (haven't run it yet) I see that this is kind of a neat way of assigning the groups in just one pass without having to go up and down in the table to find the beginning and end of each group. I really appreciate the thought that went behind this.

I that I might have a solution though. With your's, I would still need two passes. One to assign the groups and the other to do the actual record by record work that needs to be done in this unique order.

I haven't tried this but I think that, if I have two indexes, one in ASCENDING order and the other in DESCENDING order, then I could do it all in one pass something like this:

lcPrevOrd = "A"
DO WHILE !EOF()
IF indicator record = "A"
IF lcPrevOrd = "A" && Still in "A" Group.
SET ORDER TO ixASC

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,
Previous
Reply
Map
View

Click here to load this message in the networking platform