Count Lines of Source

Is there an easy way to count the number of lines of source in VB.NET 2005? Just the standard files (not the additional ones shown when selecting "Show All Files").
LVL 9
GivenRandyAsked:
Who is Participating?
 
Éric MoreauConnect With a Mentor Senior .Net ConsultantCommented:
Hi tsay,

I use http://www.mztools.com/index.htm

Cheers!
0
 
tsayCommented:
I don't think you can do this in visual studio. What you can do is copy the source, paste it in MS Word en count the lines using Tools - Word Count. Ofcourse Word will  paste sentences over multiple lines so the number won't be exact but it'll give you an idea...
HTH
0
 
SanclerConnect With a Mentor Commented:
A .vb file is just a textfile with a different extension.  So you can read it into a string, split it on crlf and count the number of elements in the resulting array.  That will then include all the empty lines, comments, etc.  But you can code to exclude those if you want something more refined.  Here's a little demo of the rough version.  One form, an OpenFileDialog (fd1) and a button

Imports System.IO
Imports System.Text.RegularExpressions
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        fd1.ShowDialog()
        Dim myFile As String = fd1.FileName
        Dim sr As New StreamReader(myFile)
        Dim contents As String = sr.ReadToEnd
        Dim lines() As String = Regex.Split(contents, vbCrLf)
        MsgBox(lines.Length)
    End Sub
End Class

Roger
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
GivenRandyAuthor Commented:
Sounds like the current way is easiest -- go to the bottom of the file and see what line number it says. :(
0
 
mastooCommented:
You can go to a command prompt and:

Type *.vb > myfile.txt

And then open myfile.txt in VS, go to the bottom, and get the total line count for that project/directory.
0
 
GivenRandyAuthor Commented:
BTW, I love using CodeRush and RefactorPro.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.