求VB统计数字出现频率的代码
看来没多少人想回答你这样的问题,这里还是给你回答一下吧,答案如下:
首先你在窗体上画一个Textbox控件数组,即 Text1(0)-Text1(15)
再画一个command1按钮和一个listbox控件,然后复制以下代码运行即可:
Private Sub Command1_Click()
Dim i As Long, ii As Long, a As Long, b As Long
List1.Clear
For i = 0 To 15
Text1(i).Tag = 0
Next
For i = 0 To 15
If Text1(i).Tag = 0 And Trim(Text1(i).Text) <> "" Then
a = 1
b = b + 1
For ii = i + 1 To 15
If Trim(Text1(ii).Text) <> "" Then
If Trim(Text1(i).Text) = Trim(Text1(ii).Text) Then
a = a + 1
Text1(ii).Tag = 1
End If
Else
Text1(ii).Tag = 1
End If
Next
List1.AddItem "数字“" & Text1(i).Text & "”有" & a & "个"
Else
Text1(i).Tag = 1
End If
Next
List1.AddItem "------------------"
List1.AddItem "总共有" & b & "个不同的数字"
List1.AddItem " (相同的只算一个)"
End Sub
运行后的效果如下图所示(是不是你要的效果了呢?):