General information
Category:
Coding, syntax & commands
>Today's Quiz. I want to maximize the number of choices I can assign to a group of records so I choose to use the alphabet through a three character field. How do I programatically increment the next assigned alphabetic character (i.e. AAA, AAB, AAC. .. AAZ then ABA, ABB, etc.)
>
>do I do this with ascii character (chr()) assignments or is there an easier way?
>
>Thanks in advance,
>
>Bill
Here is an old fox 2.6 function which uses a value in a single record file called control.dbf to create an 8 character long string used as a filename. It uses a thru z and o thru 9. I know that one may use a sys() function for a unique filename but this gives a filename which is easily identified as sequential:
FUNCTION OnePlus
PRIVATE vreturn, valreturn, vloop, vdigit, vnewfile, valias
USE Control IN SELECT(1)
IF FLOCK("Control")
vreturn = UPPER(Control->New_File)
valreturn = 0
vloop = 7
vdigit = 0
DO WHILE vloop >= 0
vdigit = ASC(SUBSTR(vreturn, 8 - vloop, 1))
valreturn = valreturn + ;
(36**vloop * IIF(vdigit > 57, vdigit - 55, vdigit - 48))
vloop = vloop - 1
ENDDO
valreturn = valreturn + 1
vloop = 7
vdigit = 0
vnewfile = ""
DO WHILE vloop >= 0
vdigit = INT(valreturn / (36**vloop))
vnewfile = vnewfile + IIF(vdigit < 10, CHR(48+vdigit), ;
CHR(55+vdigit))
valreturn = valreturn - (vdigit * 36**vloop)
vloop = vloop - 1
ENDDO
m.valias = ALIAS()
SELECT CONTROL
REPLACE Control->New_File WITH m->vnewfile
IF LEN(TRIM(valias)) <> 0
SELECT &valias
ENDIF
ELSE
vreturn = "ABORT"
ENDIF
USE IN SELECT("CONTROL")
RETURN(vreturn)
*-- EOF -- FUNCTION OnePlus
Previous
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only