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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Nth Record Selection in dBASE III

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have several databases of names and addresses, totaling 150,000 names. I need to mail to one-tenth of the total count, but don't know how to do an "nth name" selection in dBASE. I'm quite willing to export to Excel if that will make a difference.

Thanks!
 
*the following 2 lines are pseudo memory variables
*you'll need to make your own as needed.
CustFName = " "
CustLName = " "

* THIS IS THE FIRST RECORD TO READ
MYCOUNT=1

CLEAR
USE (DATABASE TO USE HERE)
GO TOP
DO WHILE 0=0
IF EOF(DATABASE TO USE HERE) THEN EXIT DO
GOTO RECNO(MYCOUNT)
* HERE'S WHERE YOU STORE THE DATABASE RECORD'S FIELD'S VALUES
* TO THE MEMORY VARIABLES YOU HAVE MENTIONED ABOVE.
CustFName = (database field-ex "FirstName")
CustLName = (database field-ex "LastName")
? CustFName + CustLName
MYCOUNT = MYCOUNT + 10 * 150,000 / 10 = 15,000 RECS TO READ
IF MYCOUNT > RECCOUNT() THEN EXIT DO
LOOP
ENDDO
CLOSE DATABASES
EXIT


The above should work, I haven't tested it yet, but it should work.

Paste the above code to a TXT file then rename the TXT to PRG and run it using DBASE.

Hoped I helped.
--MiggyD
"It's mind over matter. They don't mind so you don't matter to them."
 
Thanks! A friend suggested another option which also worked, but is not as elegant.

I created a numeric field called "N", and filled it with the record number. I created another numeric field called "REMAIND" and finally ran a routine using MOD, like so:

replace all n with recno()
replace all remaind with mod(n,10)

This put a single-digit number in REMAIND from 0 through 9. I could then COPY TO NEWFILE FOR REMAIND = 1 (or any other number I chose) to get a 1/10th selection. Crude, but it worked. The method outlined by MiggyD is a lot more clever because it allows the user to select any "n". I will use it next time. Again, thanks!


 
Here's another solution that is similar to the "remainder" technique already suggested.
In the follwoing command, substitute CHOICE with the number you require - ie in your stated case - 10. The table is then restricted to that fraction ie a CHOICE of 10 gives a tenth - every tenth record, three gives a third - every third record etc.
SET FILTER TO INT(RECNO()/CHOICE)=RECNO()/CHOICE
With the filter set, you can then perform any operation on the restricted table.
Don't forget to reset the filter before the next operation.
Hope this helps
 
well I'm glad your friend suggested it. I would like to point out that by doing it that way, you will be essentially creating a !LARGER! database--you know, copying the existing structure and adding 2 MORE fields.

But, if the drive has plenty of room then go for it. But, if you are limited on space, it would be much easier to create say a 100 to 200 byte program than it is to copy a monster of a database and pray for no "Corrupt Database" signs.

I'm from the old school where we used the KISS :-X method as much as possible. Good luck in your endeavors.

--MiggyD ::) "It's mind over matter. They don't mind so you don't matter to them."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top