计算vb程序除去注释和空白行的代码行数

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值