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!

Read a line of a file!

Status
Not open for further replies.

kruxty

Programmer
Jul 17, 2001
197
0
0
PT
I had open a file (html, in this particular case) and i want to know how i can read line by line the content of the file!
Tkx,
Kruxty :eek:)
 
{
Open "filename" for input as #1
input #1, variable
}
each time you run the input command it reads a new line so you can loop it until EOF to read the whole file

Einstiien
Einstiien@aol.com
 
A more saver way is to use Line Input #1,variable

Like
Dim strLine As String
Open "filename" For Input as 1
While Not Eof(1)
Line Input#1, strLine
Wend

Cheers
Toyman Toyman
VB Programmer
cdt@icon.co.za
 
A faster way (if you are interested in reading more than the first line) is to read the entire file in one operation and place it in an array....
[tt]
Fname$ = "MyFile.txt"
ff = FreeFile
Open Fname$ For Binary As #ff
Raw$ = String$(LOF(ff), 32)
Get #ff, 1, Raw$
Close #ff
Txt$ = Split(Raw$, vbCrLf)
[/tt]

....later, you would reference the contents of the first line with Txt$(0), the second line with Txt$(1), etc.

Note: this code was pulled from faq222-482.

VCA.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top