当前位置: 代码迷 >> 综合 >> VB2010(15)_一个简单的统计字符或单词数的应用程序
  详细解决方案

VB2010(15)_一个简单的统计字符或单词数的应用程序

热度:10   发布时间:2024-01-26 06:02:14.0

Public Class Form1
'统计字符数的函数
Private Function CountCharcters(ByVal text As String) As Integer
Return text.Length
End Function
'统计单词数的函数
Private Function CountWords(ByVal text As String) As Integer
If text.Trim.Length = 0 Then Return 0
Dim strWords() As String = text.Split(" "c)
Return strWords.Length
End Function
'从文本框中获取文本并更新显示的子过程
Private Sub UpdateDisplay()
If radCountWords.Checked Then
lblResults.Text = CountWords(txtWords.Text) & " words."
Else
lblResults.Text = CountCharcters(txtWords.Text) & " characters."
End If
End Sub
'文本框事件
Private Sub txtWords_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtWords.TextChanged
UpdateDisplay()
End Sub
'radioButton事件
Private Sub radCountWords_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles radCountWords.CheckedChanged
UpdateDisplay()
End Sub
'RadioButton事件
Private Sub radCountChars_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles radCountChars.CheckedChanged
UpdateDisplay()
End Sub

End Class

  相关解决方案