p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   VB.NET 2002/2003 Basics (http://p2p.wrox.com/forumdisplay.php?f=76)
-   -   Reading line by line from a .txt file (http://p2p.wrox.com/showthread.php?t=36889)

x_ray January 6th, 2006 03:18 PM

Reading line by line from a .txt file

i want to know how to read data from a .txt file using vb.net 2003 line by line, note that the lines have different sizes.
sorry for any inconveniences,but i am new to vb.net

Jeff Mason January 10th, 2006 12:59 PM

Look up the streamreader class (there are other ways to do what you want, but this is, I think, the simplest). Here is some example code from the help:

    ' Create an instance of StreamReader to read from a file.
    Dim sr As StreamReader = New StreamReader("TestFile.txt")
    Dim line As String
    ' Read and display the lines from the file until the end
    ' of the file is reached.
        line = sr.ReadLine()
    Loop Until line Is Nothing
Catch E As Exception
    ' Let the user know what went wrong.
    Console.WriteLine("The file could not be read:")
End Try

Jeff Mason
Custom Apps, Inc.

x_ray January 13th, 2006 02:30 PM

ok thanks jeff, but if i want write the read content to an excel file,(could you please refer to a previous topic that i posted earlier in this forum).i want to read the data from a txt file and input it into excel file(of course in a formated way)
for ex if i read aaa bbb ccc from the text file i want it stored in the excel file (as in cells)
  A B C

x_ray February 8th, 2006 02:28 PM

i found an answer for the above question now i am able to write to excel file, if anyone is interested just google a little using the keywords excel automation :)
But i have a question, i have a program that writes to a txt file, i want to develop an application that listens to this txt file and when it changes, then automatically read it and perform some I/O operation, any one have an idea?(hope it is cleat)
thanks a lot!

katsarosj February 9th, 2006 12:26 AM

Look into the FileSystemWatcher class.

x_ray February 10th, 2006 01:55 PM

ok, thanks, i will look into it and see what i can do.

All times are GMT -4. The time now is 11:57 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.