>Erik,
>
>I do not think the logic should be too hairy.
>
>Create a function that takes a letter, increments it (after
>converting it to a number), and returns two pieces of information,
>the letter it has been incremented to, and zero or one. Zero
>indicates that you do not need to anything more, 1 means you need
>to increment the next letter.
>
>Then call this function for the first digit. Return of Zero, do nothing
>with the other digits, return of 1, call the function with the next
>digit to the left, etc...., to the end. (Moving from one digit to the next
>digit to the left can be a FOR...NEXT loop).
>
>All of this can be in a wrapper function to which you pass your initial
>string, eg.. (X = WRAPPER_FUNCTION("AABC"))
>
>I did that once but not in FoxPro, and it was relatively quick
>to code.
>
>Hope it all made sense.
>
>Michel.
>
>PS: To return two pieces of information from a function, return them
>as a string and split them out.
>
>=================== Original message follows ====================
>
>>>Do you have a copy of Codebook? I'm pretty sure there's a Base36 function in there that could be adapted to what you want.
>>
>>Yeah, I do. I have looked in the book, because I thought I remembered something like that, but I didn't find it. I also did a search of my codebook projects (using my nifty SearchString tool :-)) and came up with nothing. Do you remember what the function is called?
>>
>>
>>>Otherwise just take the rightmost char, use asc() to convert it to a number, increment it, if goes over "Z" set it to A and increment the next digit to the left.
>>
>>I started laying out logic to do exactly this and it got pretty hairy. That's why I was looking for some other creatice solutions...
>>
>>Thanks for your help.
I just took this piece of code from the some old VFP 3 system which was based on the framework from Whil Hentzen's book "Programming VFP 3". This routine creates 5-character keys using the characters 48-122
Just my $0.02 :)
SELECT ITKEY
lnTimer = 1
DO WHILE (NOT RLOCK()) AND (INKEY(0.1) = 0 )
lnTimer = lnTimer + 1
IF lnTimer > lnTIMEOUT
EXIT
ENDIF
ENDDO
IF NOT RLOCK()
=messagebox("Someone else has the Key table locked - try again")
RETURN m.cRetval
ENDIF
m.cX = ITKEY.cLastKey
for i = 1 to len(m.cX)
if ! betw(asc(subs(m.cX,i,1)), 48, 122)
=messagebox("The last Key Value is not valid (" + m.cX + ") Please call your developer with this message")
retu m.cRetVal
endif
endfor
if m.cX = repl("z", len(m.cX))
m.cRetVal = "AAAAA"
else
for i = len(m.cX) to 1 step -1
if ! subs(m.cX,i,1) = "z"
m.cRetVal = subs(m.cX,1,i-1) ;
+ iif( betw(asc(subs(m.cX,i,1)), 48, 121), chr(asc(subs(m.cX,i,1)) + 1), "0" ) ;
+ repl("0",len(m.cX)-i)
m.i = 1
endif
endfor
endif
repl ITKEY.cLastKey with m.cRetVal
unlock in ITKEY
set reprocess to (m.nOldRepr)
ENDIF
Nick
Nick Neklioudov
Universal Thread Consultant
3 times Microsoft MVP - Visual FoxPro
"I have not failed. I've just found 10,000 ways that don't work." - Thomas Edison