Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Simple field rule???
Message
From
29/09/2005 16:23:09
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
To
29/09/2005 13:39:49
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 6
OS:
Windows XP
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01054488
Message ID:
01054669
Views:
21
>Yes,
>
>That would be great I only found this site today I will be happy for any assistance.
>
>Sincerely,
>
>Fred Watt

OK, then, here goes. I suggest storing the function in the database stored procedures. You will also need to create the table (included it in the database, if it needs to participate in transactions).

Regards,

Hilmar.
**********************************************************************
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