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!

Convert .dat file to string 2

Status
Not open for further replies.

ejhemler

Programmer
Aug 30, 2002
68
US
I have a file with the .dat extension that i'll call data.dat. i need to read each line in from the data.dat file into a string. for instance, i have data.dat with this in it

m4*TA012340>03/05/12:04:36:44
m4*TA012341>03/05/12:04:36:44
m4*TA012342>03/05/12:04:36:44
m4*TA012343>03/05/12:04:36:45

after the first line is converted into a string, i will break up this string so the parts are read into a table. after i read this first line in, I need that line to be deleted. Then I will continue with reading in the next line in data.dat file and so on until the data.dat file is empty. I've been working with the FileToStr() function but can't get it to work right. any suggestions? thanks.

Erik
 
If "data.dat" less than 65,000 lines you can try this, otherwise you need to adjust the code:

Code:
lcData = FileToStr('c:\temp\data.dat')
lnCounter = ALines(laData, lcData)

for i = 1 to lnCounter
   ***
   ***  Do whatever you need here

   ? laData[i]
next

Regards

-- AirCon --
 
Ejhemler,

Why do you need to delete each string after you have read it? If it is only to prevent it from being read again, you might be better using APPEND FROM. That way, you'll get each line of data into a separate record in a table, which should be much easier to manipulate than one long string.

Mike


Mike Lewis
Edinburgh, Scotland
 
If every column of data.dat has a fixed lenght (like in your example), then this is an easy way to do it:

create table data (fld1 c(2),fld2 c(1),fld3 c(2),fld4 c(6),fld5 c(1),fld6 c(8),fld7 c(1), fld8 c(8))
append from data.dat sdf

Then you can do any string manipulation. Good luck.
 
I need to delete the info from the data.dat file after i have read in the information. I will be reading in the data from the .dat file every fifteen minutes so when i go to read the information from the data.dat file again, i don't want that info from the previous read to be there anymore. Is there a way to modify .dat files with foxpro code?

Erik Hemler
 
Can you just delete the file ?
Erase data.dat

If you may not erase the file then you can do this
StrToFile('', 'data.dat')


-- AirCon --
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top