Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Auto Number
Message
From
25/05/2005 07:37:54
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
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:
01017446
Views:
22
>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.
i = 0
set order to ...
scan
  i = i + 1
  replace KeyField with i
endscan
> And after that how I make VFoxPro auto increment.

Having your own function for sequential numbers might give you more control over the details. Also, VFP does not yet have auto-incremental fields; this is available in later version - 7 or 8, I am not sure.

Here is my function, which I stored in the database stored procedures; you will also need to create the corresponding table:
**********************************************************************
FUNCTION SerialNumber(tcSequence)
	* Get serial number. Used mainly to generate primary keys.
	* The easiest way to achieve this is to call this function from a fields default value.
	* Example: default value for primary key "Client" of table "Client" = SerialNumber("Client")
	* This function accesses table SerialNumber. Fields: Sequence C(30), NextNum I.
	tcSequence = lower(tcSequence)
	local lnSelect
	lnSelect = select()
	if used("serialnumber")
		select serialnumber
	else
		select 0
		use serialnumber
	endif
	set order to "sequence"
	seek padr(tcSequence, len(sequence))
	if not found()
		append blank
		replace sequence with tcSequence, nextnum with 1
	endif
	local lnReturnValue
	if lock()
		lnReturnValue = nextnum
		replace nextnum with nextnum + 1
	else
		lnReturnValue = -1
	endif
	unlock
	select (lnSelect)
	return lnReturnValue
ENDFUNC
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Reply
Map
View

Click here to load this message in the networking platform