Opening and reading a text file line by line

In this category you can exchange your programming questions and solutions.
Post Reply
Darren
Posts: 63
Joined: Wed May 11, 2011 11:55 am

Opening and reading a text file line by line

Post: # 716Post Darren
Fri May 13, 2011 11:28 am

Please Help!!!

Can anybody tell me how i can open a text file and read it "Line by Line"?

Here is my Visual Basic 6 example.... :

    Open "C:Test.txt" For Input As #1

    Do While Not Eof(1)
          Line Input #1, N$

          Msgbox N$
    Loop

    Close

Many thanks in advance!!!

fred
Posts: 54
Joined: Thu Apr 23, 2009 10:08 am

Opening and reading a text file line by line

Post: # 717Post fred
Wed May 25, 2011 6:15 am

You can use FileStream, something like this:

dim filenaam as string
dim f as FileStream
dim line as string

filenaam = "myfile.txt"

if FileExists(filename)=true then
  f.Open(filename)
  while f.Position < f.Size
    line=f.ReadLine
    showmessage line
  wend
  f.Close
end if

Post Reply