Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Unique key generator
Message
From
04/01/2000 17:58:13
 
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00312803
Message ID:
00312825
Views:
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
>            REPLACE &cField WITH &cField + 1
>            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

You might want to make sure there is no buffering enabled for this particular table.
Fred
Microsoft Visual FoxPro MVP

foxcentral.net
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform