Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Unique key generator
Message
De
04/01/2000 18:34:11
 
 
À
04/01/2000 17:55:13
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00312803
Message ID:
00312844
Vues:
32
>>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.
>>
>>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
>>
>>    cOldAlias = ALIAS()
>>    lUsed = USED( "System" )
>>    IF ! lUsed
>>        USE SYSTEM IN 0
>>    ENDIF
>>    SELECT SYSTEM
>>    lDone = .F.
>>    DO WHILE ! lDone
>>        IF FLOCK()
>>            nReturnNum = &cField
>
>Nothing wrong with this, but try <b>nReturnNum = EVAL(cField)</b>
>
>>            REPLACE &cField WITH &cField + 1
>
>and <b>REPLACE (cField) WITH nReturnNum + 1</b>
>
>It's strictly my allergies to needless macroexpansion.
>
>>            cReturnNum = PADL( nReturnNum, nLen, '0' )
>>            UNLOCK
>>            lDone = .T.
>>        ELSE
>>            INKEY(.5)
>>        ENDIF
>>    ENDDO
>>    IF ! EMPTY( cOldAlias )
>>        SELECT (cOldAlias)
>>    ENDIF
>>    IF ! lUsed
>>        USE IN SYSTEM
>>    ENDIF
>>    RETURN cReturnNum
>>
>>
>>
>>TIA

Thanks Ed,

I was hoping for this kind of reply <s> even though it leaves me wondering how I'm getting dupes...
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform