Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Need to Combine Ascending and Descending Indexes
Message
From
25/02/1999 03:32:37
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00190759
Message ID:
00191305
Views:
15
>>>I need to set up an index to sort records using a mix of ascending and descending orders, using character fields.
>>>
>>>I recall this could be done using the SYS(15) function ("included for backward compatibility"). I've done it before, but now do not remember how! Apparently, the list of fields in the sort order would include something like "SYS(15, "ZYXW...", field)". This would cause the field to be sorted in descending order by substituting each character--a "Z" for an "A", "Y" for "B", and so forth.
>
>>sys(15) was for char. translation table but at the end what would you get ? You just try to have a descending index ?
>>AAAAAA
>>BBBBBB
>>CCCCCC
>>sorted as :
>>CCCCCC
>>BBBBBB
>>AAAAAA ? If what you want is this simple then index has a keyword descending. OTOH you can use any index descending by using "descending" keyword of "set order".
>>Cetin
>
>Thanks for writing, Cetin.
>
>I figured it out! I went back to some old code that did what I needed. I could not simply use the DESCENDING keyword, because the sort I am doing must contain _both_ ASCENDING and DESCENDING field orders.
>
>The trick is to create a variable having the entire ASCII character set in backwards order:
>
> PUBLIC gcRevSort
> gcRevSort = ''
> FOR lnPtr = 255 TO 1 STEP -1
> gcRevSort = gcRevSort + CHR(lnPtr)
> ENDFOR
>
>Next, in the INDEX expression, use the following:
>
> INDEX ON field1, field2, SYS(15, gcRevSort, field3) TAG SortName
>
>This expression allows both FIELD1 and FIELD2 to be ASCENDING sorts, while FIELD3 is a DESCENDING sort. It came in handy when I was asked to a seniority listing of employees, alphabetically by name and by seniority date, with dates listed into the past (backwards).
>
>Michael Reynolds
Michael,
I can't say I understood :( With dates I mimic descending by subtracting a future date from recorded.
index on name+str(sdate-{1/1/9999}) tag NameDate
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform