关于VB的一道题

来源:百度知道 编辑:UC知道 时间:2024/05/15 07:50:18
“输入一段文字(含中英文),要求统计出这篇文章出现次数最多和最少的字符及出现次数”,用VB或VC都行,帮忙写出程序,谢谢

'偶来
'设输入框控件名为Text1
'点击按钮即可统计字符,按钮名为Command1
'代码如下:
'自定义一个类型用于字符统计
Private Type tOwn
strC As String * 1
intCount As Integer
End Type

Private Sub Command1_Click()
If Text1.Text = "" Then Exit Sub
Dim tNew() As tOwn
ReDim tNew(0)
For i = 1 To Len(Text1.Text)
strtemp = Mid(Text1.Text, i, 1)
‘不统计空格等字符
If strtemp = " " Or strtemp = Chr(10) Or strtemp = Chr(13) Then
GoTo ne
End If
If i = 1 Then
tNew(0).strC = strtemp
tNew(0).intCount = 1
Else
Dim blHave As Boolean
blHave = False
For j = 0 To UBound(tNew)
If tNew(j).strC = strtemp Then
tNew(j).intCount = tNew(j).intCount + 1
blHave = True