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.
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.
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?
Fred,
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
skip
loop
enddo
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
You reference it just like a field, memory variable or function like date():
?recno() displays the record number
if custid = recno()
do stuff
endif
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.
Mike.
- There are an infinite number of ways to dBase your programming...
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
SCAN
replace CustID with CUSTID->CUSTID + 1;
CUSTID->CustID with CUSTID->CUSTID + 1
ENDSCAN
Then, insert my first code (with the corrected replace line) in your program for adding new customers.
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.