Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Unique key generator
Message
De
04/01/2000 19:25:00
 
 
À
04/01/2000 17:17:59
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00312803
Message ID:
00312880
Vues:
35
>Hi,
>
>I'm using this function to get unique ID numbers for various files. The "SYSTEM" file contains one record with several fields of unique numbers.

I recommend the structure changed to cTableName, nKeyValue

>
>A typical call to the function looks like this:
>
>cOrderID = NextNumber( "NxtOrderNo", 10 )
>
>The problem is I'm getting duplicate order numbers!!!
>
>Can anyone spot the reason why this might happen?
>
>Here's the function:
>
>
>    *-------------------------------------------------
>FUNCTION NextNumber
>    * get the next incremental number for the passed field, padded with
>    * leading zeros
>
>****    PARAMETER cField,nLen
lparameters cField, nLen
local cOldAlias, lUsed, lDone, nReturnNum
>
>    cOldAlias = ALIAS()
>    lUsed = USED( "System" )
>    IF ! lUsed
>        USE SYSTEM IN 0
>    ENDIF
>    SELECT SYSTEM
>    lDone = .F.
>    DO WHILE ! lDone
>        IF FLOCK()
>****            nReturnNum = &cField
>****            REPLACE &cField WITH &cField + 1
nReturnNum = eval(cField)
replace (cField) with eval(cField) + 1
>            cReturnNum = PADL( nReturnNum, nLen, '0' )
Why aren't you using integer keys?
>            UNLOCK
>            lDone = .T.
>        ELSE
>            INKEY(.5)
>        ENDIF
>    ENDDO
>    IF ! EMPTY( cOldAlias )
>        SELECT (cOldAlias)
>    ENDIF
>    IF ! lUsed
>        USE IN SYSTEM
>    ENDIF
>    RETURN cReturnNum
>
>
>
>TIA
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform