Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Creating a sequentially numbered field

Creating a sequentially numbered field

Creating a sequentially numbered field

Re: Dbase lV   I am unable to find the command to have the data in a field change for each record so that I end up with a sequentially numbered field  ie first record 1000, second record 1001, third record 1002...etc.

Any help will be appreciated.

RE: Creating a sequentially numbered field

   Are you looking for a routine to increment the number ?

RE: Creating a sequentially numbered field

Yes, I need to number each record in the database and am thinking there must be a simple way to do this on the command line.


RE: Creating a sequentially numbered field

so the field name is recordnum

RE: Creating a sequentially numbered field

For dBase IV you need to code it yourself.  The windows versions, starting with VdB 7 have an 'autoincrement' field type that does what you want, but it's not available in dBase IV.

Alternatively you could use the record number, but never, ever pack or sort your data file then.


RE: Creating a sequentially numbered field

Thanks Mike...  I thought about using the record number which actually would work for me.  Can you tell me how to get the record number to appear in  my field structure?  


RE: Creating a sequentially numbered field

It will never show up in a structure listing, but you reference it with recno().


RE: Creating a sequentially numbered field

Thanks Mike...Sorry for being so dense  but what do you mean by "reference it"

Can you tell what to enter on the command line ie. replace custid with ?recno()


RE: Creating a sequentially numbered field

   If you store recno() to mrecno, then on the next line type in replace custid with mrecno, that will do it for you. Although it would be best if you have a table that you use specifically for this.
For example if you create a table called custid, with just a numeric field in it.
Then when you are gonig to add a new record you can
sele 1
use custid
sele 2
use customers && or whatever the table is called that you are adding to
Do while Condition
sele 1
store custid+1 to mcustid
sele 2
appen blank
replace custid with mcustid
sele 1
replace custid with mcustid
sele 2

This is a rough idea of what you may need to do, bear in mind the code isnt correct but the method should work for you


RE: Creating a sequentially numbered field


You reference it just like a field, memory variable or function like date():

?recno() displays the record number
if custid = recno()
   do stuff

replace custid with recno()

But, as Aiden suggested, it's better to roll your own.  It has the advantage of being able to use any starting number you want.  Also, for recno to be a truly incrementing and unique number, you can NEVER, EVER sort or pack your table (and no one else should either - but there's nothing to stop someone).

Like Aiden suggests, create a new table, CustID, with 1 field:  CustID, Numeric, 10.0.  Add 1 record to it with the starting customer ID number, e.g. 1001.  In your program, when you are ready to add a new customer (this is different code than Aiden's but both work):

Use Customer  && or whatever the table name is.
Use CustID in 2
append blank
Replace CustID with CUSTID->CustID + 1;
        CUSTID->CustID with CustID + 1

Note:  The manual says don't replace in another work area.  This method works fine as long as the replaced field isn't in an index, as above.

- There are an infinite number of ways to dBase your programming...

RE: Creating a sequentially numbered field


2 things:  First, I realized I made a typo above.  the replace line should be:

   replace CustID with CUSTID->CUSTID + 1;
           CUSTID->CustID with CUSTID->CUSTID + 1

Second, I just reread the thread.  It looks like you're trying to assign new customer ID's.  In that case, use this code loop to add a custID to an existing customer list:

use customer
use custid in 2
   replace CustID with CUSTID->CUSTID + 1;
           CUSTID->CustID with CUSTID->CUSTID + 1

Then, insert my first code (with the corrected replace line) in your program for adding new customers.


Hope that helps

RE: Creating a sequentially numbered field

Ok, so I must be bored today...  And my reading comprehension is bad...  I reread it again, and in this case, recno() may work for you because you're just assigning a field first time:

replace all recordnum with recno() + 1000

That will make the first customer 1001, the second one 1002, etc.

Then do the extra table method above to add new customer numbers programmatically.


RE: Creating a sequentially numbered field

Yippee.. I got it.  The last suggestion worked perfectly after I changed the recno field from character to numeric.  

Thanks for the help all!


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close