Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Increment ALPHA ID's Only
Message
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Increment ALPHA ID's Only
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01220831
Message ID:
01220831
Views:
101
I am trying to get the below code to increment only an ALPHA ID field.

I know that this code is close to what I want but it just isn't quite doing the job yet. If I have a 5-character ID such as lower case "aaaaa" and I want to increment it, you would naturally say that the 5th character ought to be the letter 'b', but although I see it in the memvars, it just isn't returning the right value. I've posted on this recently but didn't come up with a satisfactory solution yet.
?IncrementAlpha("aaaaa")

FUNCTION IncrementAlpha 
LPARAMETERS pcString

lnStrLen=LEN(pcString)	&& get the string length.
LOCAL i As Integer
FOR i = 1 TO lnStrLen
   cCharToIncrement=SUBSTR(pcString,lnStrLen-i +1, 1)
   cCharToIncrement=CHR(ASC(cCharToIncrement) +1)
   IF cCharToIncrement > "z"
      cCharToIncrement = "a"
      STUFF(pcString,lnStrLen-i + 1, 1, cCharToIncrement)
   ELSE
      STUFF(pcString,lnStrLen-i + 1, 1, cCharToIncrement)
   ENDIF
ENDFOR
RETURN pcString
ENDFUNC
Next
Reply
Map
View

Click here to load this message in the networking platform