作业帮 > 综合 > 作业

vb统计在一个文本框内各英文单词出现的次数

来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/20 16:09:44
vb统计在一个文本框内各英文单词出现的次数
统计在一个文本框内各英文单词出现的次数(不区分大小写),并按英文字母的先后顺序输出各个单词与其对应的出现次数,要求将统计个单词出现的运算编写为过程.程序界面自定.
vb统计在一个文本框内各英文单词出现的次数
'把下面代码复制到窗体,添加1个list 和一个command按钮运行就可以了,和一个文本框,数据输入在文本框里
Private Type English
word As String
count As Long
End Type
'判断是不是英文
Private Function En(ByVal s As String) As Boolean
If s = "" Then En = False:Exit Function
s = LCase(s)
For i = 1 To Len(s)
a = Asc(Mid(s,i,1))
If a < 97 Or a > 122 Then En = False:Exit Function
Next
En = True
End Function
'统计数组内各个英文出现次数
Private Function TongJi(ByVal T_txt As String) As English()
s = Split(T_txt," ")
n = 0
Dim English() As English
ReDim English(0)
For i = 0 To UBound(s)
If s(i) "" And En(s(i)) = True Then
temp = False
For j = 0 To UBound(English)
If English(j).word = "" Then
English(j).word = s(i):English(j).count = 1:Exit For
ElseIf English(j).word = s(i) Then
temp = True:English(j).count = English(j).count + 1:Exit For
End If
Next
If temp = False Then
ReDim Preserve English(n):English(n).word = s(i):English(n).count = 1:n = n + 1
End If
End If
Next
TongJi = English
End Function
Private Sub Command1_Click()
Dim e() As English
e = TongJi(Text1)
Cls
For i = 0 To UBound(e)
If e(i).count > 0 Then List1.AddItem e(i).word & " 出现过:" & e(i).count & " 次"
Next
End Sub
再问: 怎么加list呀
再答: list就是列表框控件ListBox,如果你连这个都不知道,那就不要问这么难的问题好吗?