Thursday, November 17, 2011

Question:


How to display # of entries in a streamreader text file in a message box in VB08?



Answer :


Imports System
Imports System.Drawing
Imports System.Data
Imports System.IO
Imports System.Collections
Imports System.Windows.Forms
Imports System.Drawing.Printing

Public Class MainClass
    Shared Sub Main()
        Dim myReader As StreamReader

        Try
            myReader = File.OpenText("test.vb")
        Catch As IOException
            Console.WriteLine(e.ToString)
            Console.WriteLine(e.Message)
            Exit Sub
        End Try

        Dim lineCounter As Integer = 0
        Dim currentLine As String, currentData As String

        Do
            Try
                currentLine = myReader.ReadLine
                lineCounter = lineCounter + 1
            Catch As EndOfStreamException
                Console.WriteLine(e.Message)
            Finally
                currentData = currentData & currentLine & vbCrLf
            End Try
        Loop While currentLine <> Nothing

        Console.WriteLine("Number of lines read: " & lineCounter - )

        myReader.Close()
        myReader = Nothing
    End Sub
End Class


Hope this helps

No comments:

Post a Comment