Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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

Reply With Quote
  #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
Reply With Quote
  #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|

Reply With Quote
  #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!

Reply With Quote
  #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.
Reply With Quote
  #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.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:18 AM.


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