Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.OpenFileDialog1.Filter = "VB Files(*.vb)|*.vb"
Me.OpenFileDialog1.ShowDialog()
If Me.OpenFileDialog1.FileName IsNot Nothing Then
Me.txtFileName.Text = Me.OpenFileDialog1.FileName
LoadFile(Me.txtFileName.Text.Trim)
End If
End Sub
''' <summary>
''' LoadFile
''' </summary>
''' <param name="FileName">FileName</param>
''' <remarks></remarks>
Public Sub LoadFile(ByVal FileName As String)
Dim mFileOpen As New System.IO.StreamReader(FileName)
Dim iLineCount As Integer = 0
Dim iTotalLine As Integer = 0
Dim strLine As String
Do While True
strLine = mFileOpen.ReadLine()
If strLine IsNot Nothing Then
If strLine.Trim <> "" AndAlso Not strLine.TrimStart.StartsWith("'") AndAlso Not strLine.TrimStart.StartsWith("#") Then
iLineCount += 1
iTotalLine += 1
Else
iTotalLine += 1
End If
Else
Exit Do
End If
Loop
Me.ShowResult.Text = "The Total Line of this vb file is:" & iTotalLine & vbCrLf & _
"The Total Line of this vb file (not including the comments and blank rows) is:" & iLineCount
End Sub
End Class
转载于:https://www.cnblogs.com/janejane/archive/2012/03/03/2378388.html