Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Incrementing Alphabet
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00094857
Message ID:
00094859
Views:
23
>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
I won't begin to flatter myself that this is the best way but this is what I do with my id fields. The ascii incrementing sounds far slicker.
- Sarah :>
PROCEDURE idupd8
****************
*// update the id field to the next letter, checked on startup
PRIVATE m.lccode,m.lcletter
IF !USED('books')
SELECT 0
USE bksystem!books.sys SHARED
ENDIF

IF books.number > 9998000

m.lccode = books.code
m.lcletter = SUBSTR(m.lccode,3,1)
m.lcletter = nextletter(m.lcletter)
m.lccode = LEFT(m.lccode,2)+m.lcletter

IF m.lcletter = 'A'
m.lcletter = SUBSTR(m.lccode,2,1)
m.lcletter = nextletter(m.lcletter)
m.lccode = LEFT(m.lccode,1)+m.lcletter+RIGHT(m.lccode,1)
IF m.lcletter = 'A'
m.lcletter = SUBSTR(m.lccode,2,1)
m.lcletter = nextletter(m.lcletter)
m.lccode = m.lcletter+RIGHT(m.lccode,2)
ENDIF
ENDIF

REPLACE books.code WITH m.lccode;
books.number WITH 1

ENDIF

USE IN BOOKS
USE books.sys shared

RETURN

FUNCTION nextletter
*******************
*// Used by IDUpd8 to make sure the internal id's are right

PARAMETER pletter
PRIVATE m.lcoutput
DO CASE
CASE pletter = 'A'
m.lcoutput = 'B'
CASE pletter = 'B'
m.lcoutput = 'C'
CASE pletter = 'C'
m.lcoutput = 'D'
CASE pletter = 'D'
m.lcoutput = 'E'
CASE pletter = 'E'
m.lcoutput = 'F'
CASE pletter = 'F'
m.lcoutput = 'G'
CASE pletter = 'G'
m.lcoutput = 'H'
CASE pletter = 'H'
m.lcoutput = 'I'
CASE pletter = 'I'
m.lcoutput = 'J'
CASE pletter = 'J'
m.lcoutput = 'K'
CASE pletter = 'K'
m.lcoutput = 'L'
CASE pletter = 'L'
m.lcoutput = 'M'
CASE pletter = 'M'
m.lcoutput = 'N'
CASE pletter = 'N'
m.lcoutput = 'O'
CASE pletter = 'O'
m.lcoutput = 'P'
CASE pletter = 'P'
m.lcoutput = 'Q'
CASE pletter = 'Q'
m.lcoutput = 'R'
CASE pletter = 'R'
m.lcoutput = 'S'
CASE pletter = 'S'
m.lcoutput = 'T'
CASE pletter = 'T'
m.lcoutput = 'U'
CASE pletter = 'U'
m.lcoutput = 'V'
CASE pletter = 'V'
m.lcoutput = 'W'
CASE pletter = 'W'
m.lcoutput = 'X'
CASE pletter = 'X'
m.lcoutput = 'Y'
CASE pletter = 'Y'
m.lcoutput = 'Z'
CASE pletter = 'Z'
m.lcoutput = 'A'
ENDCASE

RETURN m.lcoutput
Sarah King
pcpropertymanager.com
Previous
Reply
Map
View

Click here to load this message in the networking platform