Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Auto Number
Message
From
25/05/2005 07:39:47
 
 
To
25/05/2005 07:21:14
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:
01017448
Views:
24
>I have this table with almost 2,000 record and, I need to re-orde and assign a sequencial number but I need to know if I can do it with some routine not manually. And after that how I make VFoxPro auto increment.
>
>V/R
>R. De Jesus

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
- Whoever said that women are the weaker sex never tried to wrest the bedclothes off one in the middle of the night
- Worry is the interest you pay, in advance, for a loan that you may never need to take out.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform