Mega Code Archive

 
Categories / VB.Net / File Directory
 

Open Text file and count the lines

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 e 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 e As EndOfStreamException                 Console.WriteLine(e.Message)             Finally                 currentData = currentData & currentLine & vbCrLf             End Try         Loop While currentLine <> Nothing         Console.WriteLine("Number of lines read: " & lineCounter - 1 )         myReader.Close()         myReader = Nothing     End Sub End Class