VB.NET 2002/2003 BasicsFor coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.
You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
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
thanks
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:
Code:
Try
' 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.
Do
line = sr.ReadLine()
Console.WriteLine(Line)
Loop Until line Is Nothing
sr.Close()
Catch E As Exception
' Let the user know what went wrong.
Console.WriteLine("The file could not be read:")
Console.WriteLine(E.Message)
End Try
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
|aaa|bbb|ccc|
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!