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

how can i use text file as a database

Status
Not open for further replies.

promizez

MIS
May 6, 2007
4
PH
good day expert...

can any one help me solve this one with a code..
by the way, i am using foxpro 2.6

here's the problem..
how can i read the content of a text file, line by line? just like doing a search in a database, and prompt/display the data once its being found/match from a variable.

basically i want to treat the text file as a database. the data in each line is separated by a comma(,)

sample content of my text file(modem1.txt):

Michael_Jackson,ATZ0,2,3
Spider_Man,ATZ1,1,2
Super_Man,AZT2,3,2
Bat_Man,A2TZ,1,2
Super_Girl,BTZ1,1,2


hope you can help me with this one.
thanks in advance.
 
create a cursor, then append.

create cursor 'curtemp' ;
(;
line1 C(20),;
line2 C(20),;
line3 n(10),;
line4 N(10);
)

APPEND FROM 'fullpath\MODEM1.TXT' delimited
 
[ ]

Are you going to read in the whole text file or are you wanting to selectively read in specific lines?



mmerlinn


"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Steven Raymond
 
It is one thing to do a one-time read of a text file and use it as data.

When you say... "treat the text file as a database". I assume that instead of "database", which is a container for one or more data tables, you mean "Data Table" - where the data 'lives'.

Getting data out of and back into a text file might be OK for a one-time or occasional event, but on an ongoing basis, that is not a good idea.

Data within a text file cannot be searched effectively using Indexes, etc. on the data. Nor are there 'real' fields for the data itself.

Stirfry's suggestion above is the best approach. Define the recipient data table to contain the fields needed and which are represented by the text 'data'. Then do an APPEND to input the data for use in your FP application.

Good Luck,
JRB-Bldr
 
JRB-Bldr said:
I assume that instead of "database", which is a container for one or more data tables, you mean "Data Table" - where the data 'lives'.
JRB-Bldr, isn't this VFP terminology?
I don't think the concept of a container was already there in FoxPro 2.6.
But I clearly remember that .DBF files were referred to as databases.
I justed checked, too - I still have a hard copy of FoxPro 2.0 documentation around (copyrighted in 1989 and 1991).
 
alvechurchdata said:
"The name of the database in the current workarea is returned"
Exactly.

alvechurchdata said:
And I'd always assumed that "dbf" stood for "data base file".
Geoff, it used to. Technically, it still is - after all, a table is still one of the database files :).

It's just that when VFP was introduced, the concept of a database shifted to mean a container for the tables, not a single table itself, and it changed the terminology, so it sometimes hard to remember that it was different once. But some folks still use old FoxPro, and we have to keep that in mind (not an easything to do, though).
 
It will be easier if you use Stirfry's suggestion. If that is not an option use the Low level file options like FOPEN(), FREAD() etc. I think they were available in fox 2.6.
 
Technically, it still is - after all, a table is still one of the database files

I suppose the term is technically correct but it's deeply misleading to a naive user. I was using databases when I first met Fox and, much as I loved the original old vulpine, it wasn't really a database.

Geoff Franklin
 
Very simply!

1. You have e.g. myfile.txt
2. Create any new table, e.g. myfile.dbf with
one field e.g. for 150 characters
3. Use myfile.dbf
append from myfile.txt type sdf
browse width 150

I use it some years.

Stefan


 
Stefan - What you describe does indeed input text file data into a data table (OK - "database" by the OLD terminology), but it does not "use text file as a database"

From what you describe, all subsequent operations would be (AND SHOULD BE) on the data table, not the text file itself.

Good Luck,
JRB-Bldr
 
You wanted => how can i read the content of a text file, line by line?

If you make *append from modem1.txt type sdf* the result would be 5 records in the new table. Because one record=1 line, then you can "read the content of your text file, line by line" as you wanted (now your new table has 1 colum and 5 lines = records).

TABLE NAME= MODEM1.dbf
record 1=line1 : Michael_Jackson,ATZ0,2,3
record 2=line2 : Spider_Man,ATZ1,1,2
record 3=line3 : Super_Man,AZT2,3,2
record 4=line4 : Bat_Man,A2TZ,1,2
record 5=line5 : Super_Girl,BTZ1,1,2

In addition, if you want you can create MODEM1.dbf with 3 collums (fields) using the fact the delimitation is marked by commas (,).

Following, you can write prg-file for tranfering the records back into text file modem1.txt

DELIMITED [WITH TAB | WITH <delimiter> | WITH BLANK]
A DELIMITED file is an ASCII text file in which each record ends with a carriage return and linefeed. Field contents are by default assumed to be separated from each other by commas, and character field values to be additionally delimited by double quotation marks. For example:
"Smith", 9999999, "TELEPHONE"




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top