Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
| Search | Today's Posts | Mark Forums Read
VB.NET 2002/2003 Basics For 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
  #1 (permalink)  
Old January 6th, 2006, 03:18 PM
Authorized User
 
Join Date: Nov 2005
Location: , , .
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to x_ray
Default Reading line by line from a .txt file

Hi,

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

  #2 (permalink)  
Old January 10th, 2006, 12:59 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Hudson, MA, USA.
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
  #3 (permalink)  
Old January 13th, 2006, 02:30 PM
Authorized User
 
Join Date: Nov 2005
Location: , , .
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to x_ray
Default

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|

  #4 (permalink)  
Old February 8th, 2006, 02:28 PM
Authorized User
 
Join Date: Nov 2005
Location: , , .
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to x_ray
Default

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!

  #5 (permalink)  
Old February 9th, 2006, 12:26 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Look into the FileSystemWatcher class.
  #6 (permalink)  
Old February 10th, 2006, 01:55 PM
Authorized User
 
Join Date: Nov 2005
Location: , , .
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to x_ray
Default

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to draw indicator line in owc line chart AlexOo General .NET 0 July 9th, 2007 10:32 PM
Reading txt file umeshtheone SQL Server 2000 9 May 15th, 2007 12:43 AM
Reading a string from line by line vaidyapragati ASP.NET 2.0 Professional 1 May 3rd, 2007 08:43 AM
How to read file line by line in EVC++ iriskab Visual C++ 0 September 27th, 2006 01:39 PM
Import txt starting at a specific line lookin VB How-To 5 March 29th, 2006 11:53 AM





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