Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Serial Number with A-Z
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00394168
Message ID:
00394371
Vues:
14
I like it most.
********************************************************************
*  Description.......: GetSerialNumber
*  Calling Samples...: GetSerialNumber('ABCDE','BASE62')
*  Parameter List....: pcOldVal, pcOpt, pcCharList
*  Created by........: Sergey Berezniker sergeyb@isgcom.com 
*  Modified by.......: 
********************************************************************
* Purpose   Creates next string key from the passed one 
*               using specified set of characters 
*            
*  Param's  
*    1 - Current Key
*    2 - defines the list of allowed characters
*         BASENN - See DO CASE in the body of the program
*     CUSTOM - the list of character as parameter 3
*            3 - List of characters
*            
*            
*   Return  New Key
*            
*    Note : Routine ignores (doesn't change) the positions 
*                    with the characters not in the specified list

PARAMETER pcOldVal, pcOpt, pcCharList

PRIVATE cNewVal, i, cDigits, cLetters, nStrLen, cOldChar, cNewChar

pcOpt = IIF(EMPTY(pcOpt), "BASE10", UPPER(pcOpt))
* Fill out the string 'cCharList' with all characters
cDigits = "0123456789"
cLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

DO CASE
CASE "CUSTOM" $ pcOpt
     cCharList = pcCharList
CASE "BASE10" $ pcOpt
     * Just Digits
     cCharList = cDigits
CASE "BASE16" $ pcOpt
     * Hex-dec
     cCharList = cDigits + "ABCDEF"
CASE "BASE26L" $ pcOpt
     * Lower case letters
     cCharList = LOWER(cLetters)
CASE "BASE26" $ pcOpt
     * Upper case letters
     cCharList = cLetters
CASE "BASE36L" $ pcOpt
     * Digits + Lower case letters
     cCharList = cDigits + LOWER(cLetters)
CASE "BASE36" $ pcOpt
     * Digits + Upper case letters
     cCharList = cDigits + cLetters
CASE "BASE52" $ pcOpt
     * All letters
     cCharList = cLetters + LOWER(cLetters)
CASE "BASE62" $ pcOpt
     * Digits + All letters
     cCharList = cDigits + cLetters + LOWER(cLetters)
OTHERWISE
     * The same as BASE10
     cCharList = cDigits
ENDCASE     

nStrLen = LEN(cCharList)

cNewVal = pcOldVal

* Scan Val string from the right to the left

FOR i = LEN(cNewVal) TO 1 STEP -1

     cOldChar = SUBSTR(pcOldVal, i, 1)

     IF NOT (cOldChar $ cCharList)
          * Keep it 
          LOOP
     ENDIF

     * Get the next character for this position
     cNewChar = GetNextChar( cOldChar )

     cNewVal = STUFF(cNewVal, i, 1, cNewChar) 
     IF cNewChar <> LEFT(cCharList,1)          
          * We got next one
          EXIT
     ENDIF

ENDFOR

RETURN cNewVal
**********************************************

PROCEDURE GetNextChar     
* Get the next character inthe cCharList or the first one 

PARAM pcOneChar

PRIVATE nPos

nPos = AT(pcOneChar, cCharList)

IF nPos = nStrLen          
     * It's last character
     pcOneChar = LEFT(cCharList,1)
ELSE                         
     * Get the next character
     pcOneChar = SUBSTR(cCharList, nPos+1,1)
ENDIF

RETURN pcOneChar
>>I need a serial # scheme that works like newid(), But uses Letters as well as numbers. Anyone have some code or know where I can get it.
>>Oh i'm using vfp 5
>>
>> Thanks Kelly
>

>Kelly,
>
>The program above should give you some pointers.
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform