Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Unique key generator
Message
De
04/01/2000 17:55:13
 
 
À
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:
00312824
Vues:
24
>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
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform