Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Alphabetic numbering system
Message
From
08/01/1999 13:11:16
 
 
To
08/01/1999 12:07:05
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00174074
Message ID:
00174114
Views:
25
Erik,

I had developed the following function for an application requiring similar functionality. Instead of using the 26 alpha characters (A-Z), it uses 224 characters (CHR(32) through CHR(255)). However, the basic concept is the same, and the changes needed to the function are minimal. In effect, you are using a base-26 numerical system, where each ordinal position of the "number" string can have a value of 0 to 25. Because you are representing each ordinal position with an ASCII character ranging in value from 65 to 90, the "increment" function needs to translate each ordinal character from its ASCII value to its ordinal value, perform the increment, then translate each character back to its ASCII representation.

****************************************************************************
* FUNCTION IncrementCode
*
* Description: Takes a character string parameter and "increments" its
* numeric value, and returns the incremented value as a
* character string. Only the characters from #32 to #255
* are used. Therefore, an empty string (all blanks) will
* have the numeric value of 0.
****************************************************************************
FUNCTION IncrementCode
PARAMETER m.lastcode && The string value to increment

PRIVATE m.setdeci, m.i, m.err, m.codevalue, m.nextcode, m.numbase

#DEFINE MAXLEN 4 && Length of numeric string (corresponds with
&& field width)
#DEFINE MINASCII 32 && Minimum ASCII ordinal value (the 0 value)
#DEFINE MAXASCII 255 && Maximum ASCII ordinal value.

IF TYPE("m.lastcode") <> "C"
m.lastcode = "" && Make sure m.lastcode is type character
ENDIF
m.numbase = MAXASCII - MINASCII + 1
m.lastcode = PADL(m.lastcode,MAXLEN,CHR(MINASCII))
m.codevalue = 0 && Initialize numeric value of string parameter
m.err = .F.
FOR m.i = 1 TO MAXLEN
IF SUBSTR(m.lastcode,m.i,1) >= CHR(MINASCII)
m.codevalue = m.codevalue +;
(ASC(SUBSTR(m.lastcode,m.i,1)) - MINASCII) * ;
m.numbase^(MAXLEN - m.i)
ELSE
m.err = .T.
ENDIF
ENDFOR
IF NOT m.err
m.setdeci = SET("DECIMALS")
SET DECIMALS TO 18
m.codevalue = m.codevalue + 1 && Increment the code value
m.nextcode = "" && Initialize result code string
FOR m.i = 1 TO MAXLEN
m.nextcode = CHR(INT((m.codevalue % m.numbase^m.i) / ;
m.numbase^(m.i - 1)) + MINASCII) + m.nextcode
ENDFOR
SET DECIMALS TO m.setdeci
ELSE
* On error, return a "zero" value string.
*
m.nextcode = REPLICATE(CHR(MINASCII), MAXLEN)
ENDIF
RETURN m.nextcode
#UNDEF MAXLEN
#UNDEF MINASCII
#UNDEF MAXASCII
Previous
Reply
Map
View

Click here to load this message in the networking platform