Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Alphabetic numbering system
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00174074
Message ID:
00174123
Views:
26
>I am faced with the need to create (actually participate with) an alphabetic numbering system. The sequence is straight forward, and looks like this:
>
>AAAA
>AAAB
>.
>.
>AAAZ
>AABA
>
>etc.
>
>Really my only need is to be able to increment these codes by one, so I need a function that receives "DPRZ" and returns "DPSA". Get it?
>
>I am fairly confident that I can pound out the code to do this, but all of my ideas so far would take an enormous amount of code- can anybody think of a practical solution?

Hiya Erik,

Since everyone seems to be joining the fun, I can't resist a problem like this. Whaddya think of:
* FUNCTION IncrChar
* AUTHOR: George Tasker
* DATE: January 8, 1999 - 1:26 PM
* PURPOSE: 

LPARAMETER pcChars

LOCAL lcresult, lcrightmost, lcbase, lnlength
lnlength = LEN(pcChars)
lcrightmost = CHR(ASC(RIGHT(pcChars, 1)) + 1)
IF lnlength > 1
  lcbase = LEFT(pcChars, LEN(pcChars) - 1)
  IF lcrightmost > "Z"
    lcresult = IncrChar(lcbase) + "A"
  ELSE
    lcresult = lcbase + lcrightmost
  ENDIF
ELSE
  IF lcrightmost > "Z"
    lcresult = "AA"
  ELSE
    lcresult = lcrightmost
  ENDIF
ENDIF
RETURN lcresult
No loops, no muss, no fuss. It'll automatically icrease the length by one when it gets to "ZZZZ" or the like.
George

Ubi caritas et amor, deus ibi est
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform