Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Auto Number
Message
From
25/05/2005 11:03:34
 
 
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Environment versions
Visual FoxPro:
VFP 6 SP5
OS:
Windows NT
Network:
Windows NT
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01017435
Message ID:
01017528
Views:
24
Have you tried this in a busy environment? Seems to me that the SET REPROCESS would cause problems.

>
>Ramon
>
>Below is code for function NewID(). You can use this for AutoIncrement of a table's PK. Just put NewID() as the Default value for the field in the table designer.
>You need a table (Counter) with 2 fields: TableName + Counter (Integer)
>You can supply the subject table name (for the incrementing key val) as a param, or the fn. will take the current selected table. If there IS no entry in the counter table, for the subject table, it will create on for you.
>
>For the assigning a seq. number to your 2000 recs: in a scan loop you could use each rec's RECNO() to assign it to the field, or also use NewID(), e.g.
>
>
>SCAN
>  Replace MyPK with NewID()
>EndSCAN
>
>
>HTH
>
>Terry
>
>NewID
>________
>
>FUNCTION NewID( tnStartID, tcAlias )
>
>*Set PATH to FULLPATH('DATA')
>
>LOCAL lcAlias, lcOldReprocess, lnOldArea, lnCounter, lnStartID
>
>lnOldArea = SELECT()				&& Save current work area
>
>IF PARAMETERS() < 1					&& Did we get an alias passed?
>    lcAlias 	= LOWER( ALIAS())	&& If not, take the current one
>    lnStartID	= 1
>ELSE								&& At least 1 param passed
>    lnStartID	= tnStartID	
>    If PARAMETERS() = 2				&& Alias passed?
>        lcAlias = LOWER( tcAlias)
>    Else
>        lcAlias = LOWER( ALIAS())
>    Endif
>ENDIF
>
>lcOldReprocess 	= SET('REPROCESS')
>SET REPROCESS TO AUTOMATIC			&& Lock until user presses Esc
>
>IF NOT USED( "COUNTER")
>    USE COUNTER IN 0 EXCLUSIVE
>ENDIF
>SELECT COUNTER
>
>IF not SEEK( lcAlias, "COUNTER", "TableName")
>    INSERT into COUNTER (TableName, Value) values ( lcAlias, lnStartID)
>ELSE
>    IF RLOCK()
>	REPLACE COUNTER->value WITH COUNTER->value + 1
>	UNLOCK
>    ENDIF
>ENDIF
>lnCounter = COUNTER.value
>USE	
>	
>SELECT (lnOldArea)
>SET REPROCESS TO lcOldReprocess
>
>RETURN lnCounter
>ENDFUNC
>
>
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform