Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Autoincrementing number on table
Message
De
01/07/2005 09:45:40
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP1
Network:
Windows 2000 Server
Database:
Visual FoxPro
Divers
Thread ID:
01028122
Message ID:
01028126
Vues:
15
This message has been marked as the solution to the initial question of the thread.
>I am trying to create a table of users for my application. I have 2 fields one named userno and one named username. How can I automatically create the usernumber when creating the user. therefore autocrement the number by one each time. Is this possible?

In VFP 8 and later there is an autoincremental field.

To have more control (or for older versions), you can use a sequence function, that stores the sequences in a separate table. Here is my function, which I store in the DB stored procedures; you will need to create the table too:
**********************************************************************
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)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform