Read 1st line of text file

hardrock

Registered User.
Local time
Today, 23:37
Joined
Apr 5, 2007
Messages
166
Hi guys, a simple problem. My text file contains 1 line of data, i simply want access to open the text file and dump the contents into strtemp. My code below doesn't seem to do that. Please can someone help?

TmpFile = "c:\results.txt"
Open TmpFile For Output As #1
Input #1, strtemp

Close #1
 
TmpFile = "c:\results.txt"
Open TmpFile For Output As #1
Input #1, strtemp

Close #1

doh

you opened the file for output (ie you are writing ot the file - then tried to read from it!
then you need line input ... not just input

try this


Code:
dim strtemp as string

TmpFile = "c:\results.txt"
Open TmpFile For input As #1
line Input #1, strtemp

Close #1
 
Line Input will work.

But, it is predicated on the carriage-return. If one had a file that used
line-feeds as terminators it would read the entire file.

But the original intent here is to read the entire file.

Just wanted to add the line terminator bit as it will crop up if you process
enough files.

Wayne
 

Users who are viewing this thread

Back
Top Bottom