C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Visual Studio »

Open an Text File and Count the No of Line in VB.Net


Posted Date: 03 Jul 2009    Resource Type: Code Snippets    Category: Visual Studio
Author: R.VijayaragavanMember Level: Gold    
Rating: 1 out of 5Points: 8 (Rs 5)



Abstract:


Create an text file and count the no of line to read from text file.

Description:


To create an text file and count the no of line to read from text file in VB.net.

Code:




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

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

Try
myReader = File.OpenText("TextFile.txt")
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 : " & lineCounter - 1 )

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





Responses

Author: Miss Meetu Choudhary    03 Jul 2009Member Level: Diamond   Points : 1
Format your resources Properly to get good points and more readers.


++

Thanks and Regards
Meetu Choudhary
Site Coordinator.


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Open an Text File and Count the No of Line in VB.Net  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Cretae Runtime Updatepanel,Label
Previous Resource: How to execute a Batch file in Asp.net
Return to Discussion Resource Index
Post New Resource
Category: Visual Studio


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use