Discussion:
enumerating instances in dbf file
(too old to reply)
scooter6
2005-12-22 16:44:38 UTC
Permalink
I have a dbase file that has a field called 'zip' - there are (can be)
multiple instances of a zip code.

What I'm trying to do is create another file that adds the enumeration
of how many times the zip code was in this dbf file.

For instance, I have a file called workfile.dbf, and it looks like
this

Field Names:

Zip Message
------- -------------
10001 100A
10002 200A
10002 300A
10003 400A
10003 500A
10003 600A

I am trying to write a program that creates a new dbf file called
sqwork and it needs to look like this:

Field Name:

Zipseqno Message
------------- -------------
100011 100A
100021 200A
100022 300A
100031 400A
100032 500A
100033 600A

As you can see, the file I want to create needs to have the zip code
from the first file and have the 'occurence' added to the end of it -
so in my example above, there are three (3) instances of zip code 10003
- so the file I need created has zipseqno 100031, 100032 & 100033

Can anyone tell me how I can accomplish this with a .prg ??

I am using dBase III on Unix
thanks

Scott
r bevers
2006-05-27 10:04:00 UTC
Permalink
Post by scooter6
I have a dbase file that has a field called 'zip' - there are (can be)
multiple instances of a zip code.
What I'm trying to do is create another file that adds the enumeration
of how many times the zip code was in this dbf file.
For instance, I have a file called workfile.dbf, and it looks like
this
Zip Message
------- -------------
10001 100A
10002 200A
10002 300A
10003 400A
10003 500A
10003 600A
I am trying to write a program that creates a new dbf file called
Zipseqno Message
------------- -------------
100011 100A
100021 200A
100022 300A
100031 400A
100032 500A
100033 600A
As you can see, the file I want to create needs to have the zip code
from the first file and have the 'occurence' added to the end of it -
so in my example above, there are three (3) instances of zip code 10003
- so the file I need created has zipseqno 100031, 100032 & 100033
Can anyone tell me how I can accomplish this with a .prg ??
I am using dBase III on Unix
thanks
Scott
Hello Scot

This problem can be easyly solved
Ive added a sample of some code written in foxpro for windows.

SET SAFETY OFF


CLOSE ALL

* create an input table
CREATE TABLE testinput (zip c(5) , bericht c(4), iteller n(4))
* fill the table with contents of your file
APPEND FROM "input.txt" sdf

* sort the table on zip code
SELECT * from testinput ORDER BY zip INTO TABLE testinput1
use testinput1



GO top
hzip = zip
teller = 1
* loop through the file till the end of the file
* i think this would be in dbase something like "while not eof()"

SCAN
* if the zip changes we start counting from 1 again.
IF hzip <> zip
hzip = zip
teller = 1
replace iteller with teller
teller = teller + 1
ELSE
replace iteller with teller
teller = teller + 1
endif
endscan
browse

*********************************************************************
Ofcource you do instead of "replace iteller with teller" a line like
"replace zip with zip + ltrim(str(iteller))"

Succes

The acutual content of the input.txt file

10001100A
10002200A
10002300A
10003400A
10003500A
10003600A

Loading...