Wrox Programmer Forums
|
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
 
Old December 8th, 2003, 04:42 PM
dag dag is offline
Registered User
 
Join Date: Dec 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Catch Problem

Using this code from Chapter 11 Page 472:
        Do
            Try
                ' Read a line from the file...
                currentLine = myReader.ReadLine
                lineCounter = lineCounter + 1
            Catch e As EndOfStreamException
                ' Display the message...
                MessageBox.Show(e.Message)
                ' Exit the Do loop...
                Exit Do
            Finally
                ' Concatenate the data to the strData variable...
                currentData = currentData & currentLine & vbCrLf
            End Try
        Loop While currentLine <> Nothing

The text file I am reading has blank lines in it.
Sample:

Line one <CrLf>
Line two <CrLf>
<CrLf>
Line Four <CrLf>
Line Five <CrLf>
Line Six <CrLf>

When the code reaches Line Four it exit the loop because currentLine = Nothing.

I want to read all the lines (one at a time) and exit the loop when I have reached the end of the file. I still want to read past the blank lines.

If I use a straight loop without the "While currentLine <> Nothing" the "Catch e As EndOfStreamException" does not catch the end of stream exception!

How can I read the stream, one line at at time, and process "ALL" the lines in the file?

 
Old December 8th, 2003, 09:28 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 336
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alyeng2000
Default

depend while loop check on reader status not on currentline

Ahmed Ali
Software Developer





Similar Threads
Thread Thread Starter Forum Replies Last Post
Try...Catch lowell VB.NET 3 July 23rd, 2007 06:35 AM
Try/Catch/Finally rohit.sharma C# 2 January 12th, 2007 11:44 PM
Try Catch not working?? dparsons ASP.NET 1.0 and 1.1 Professional 3 September 18th, 2006 06:54 PM
Try and Catch? mujju PHP How-To 2 January 20th, 2005 12:27 PM
Try... Catch... End Try stu9820 ASP.NET 1.0 and 1.1 Basics 4 April 3rd, 2004 11:05 PM





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