Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Increment Table Column

Status
Not open for further replies.

asm338s

Programmer
Jul 16, 2001
135
US
How can I increment a columns value from within the table designer? I am planning on using that as an index. I am appending the rest of the columns in the table from another table, except the sequence number which should be incremented automatically every time a new record is appended.

Thanks
 
Assuming you are using tables in a DBC, you can use the DEFAULT value to call a Stored Procedure to return a unique ID. See the TASTRADE Application that comes with the MSDN Sample Code. If installed properly, you can:

DO (_samples+"\tastrade\tastrade")

The VFP system variable _samples on my system has a value of:
C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\MSDN\2001APR\1033\SAMPLES\VFP98

In the Behind the Scenes, Choose All, then choose NewID() from the Design Feature list. Press the Code button to really see how it's done.

Bottomline, with VFP you have the flexibility to do it any way you want - not just the way someone else has decided is "right".

Rick
 
Can i just not say in the expression box in the table design window : something like sequence = sequence + 1
 
No. This is not Access - were one solution "fits all". VFP is for developers, NOT end users, and with flexibility comes responsibility for an appropriate design. Once you build (or buy) a framework that makes sense for the type of applications you develop, then it can really be simpler to implement than what you are suggesting should work.

(Now getting off my soap box - sorry about that.)

Rick
 
You might also check out the MODIFY STRUCTURE command it can give you that cability, but you will have to right a lot of audit code if the tables aren't blank when you start. And you will have to know how to use "macro substituton" For example:

? SET("EXACT") &&current setting of EXACT
a = SET("EXACT") &&store setting of EXACT in variable a
SET EXACT A &&Generates an error
SET EXACT &A &&Uses macro substitution and works

You will have to automate the building of strings of commands and implement them with MODIFY STRUC or CREATE TABLE using macro substition.
-Pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top