求VB统计数字出现频率的代码
求VB统计数字出现频率的代码:有多个text(如16个),16个text里面有某个数字,统计每个数字出现的次数,并在list1里次数如1出现多少次,2出现多少次从多到少显...
求VB统计数字出现频率的代码:有多个text(如16个),16个text里面有某个数字,统计每个数字出现的次数,并在list1里次数如1出现多少次,2出现多少次 从多到少显示出来 vb代码急
展开
2个回答
展开全部
假设16个text为控件组text1(0-15)
Private Sub Command1_Click()
Dim ss As String, s1 As String, S2 As String, s3 As String, s5 As String, s6 As String
Dim sL As Variant, sLL As Variant, sLS As Variant, i As Long, K As Long, l As Long
Dim MP1 As Long, MP2 As Long, MP3 As Long
ss=","
for i =0 to 15
ss=ss & text1(i).text & ","
next
sL = Split(ss, ",")
K = Len(Trim(ss))
For i = 0 To UBound(sL)
If Len(sL(i)) <> 0 Then
s1 = "," & sL(i) & ","
S2 = ss
Do While InStr(1, S2, s1) > 0
S2 = Replace(S2, s1, ",,")
Loop
l = (K - Len(S2)) / Len(sL(i))
s6 = s6 & "," & l & "/" & sL(i)
End If
Next
sLL = Split(s6, ",")
For i = 0 To UBound(sLL)
For K = i + 1 To UBound(sLL)
If sLL(i) <> "" Then
MP1 = Mid(sLL(K), 1, InStr(1, sLL(K), "/") - 1)
MP2 = Mid(sLL(i), 1, InStr(1, sLL(i), "/") - 1)
If MP1 > MP2 Then
s5 = sLL(i)
sLL(i) = sLL(K)
sLL(K) = s5
End If
End If
Next
Next
ss = ""
For i = UBound(sLL) To 0 Step -1
For K = i - 1 To 0 Step -1
If sLL(K) = sLL(i) Then
sLL(i) = ""
ss = ss & "," & sLL(i)
End If
Next
Next
For i = 0 To UBound(sLL)
If sLL(i) <> "" And K < 5 Then
List1.AddItem Replace(sLL(i), "/", "次:"), List1.ListCount
End If
Next
End Sub
Private Sub Command1_Click()
Dim ss As String, s1 As String, S2 As String, s3 As String, s5 As String, s6 As String
Dim sL As Variant, sLL As Variant, sLS As Variant, i As Long, K As Long, l As Long
Dim MP1 As Long, MP2 As Long, MP3 As Long
ss=","
for i =0 to 15
ss=ss & text1(i).text & ","
next
sL = Split(ss, ",")
K = Len(Trim(ss))
For i = 0 To UBound(sL)
If Len(sL(i)) <> 0 Then
s1 = "," & sL(i) & ","
S2 = ss
Do While InStr(1, S2, s1) > 0
S2 = Replace(S2, s1, ",,")
Loop
l = (K - Len(S2)) / Len(sL(i))
s6 = s6 & "," & l & "/" & sL(i)
End If
Next
sLL = Split(s6, ",")
For i = 0 To UBound(sLL)
For K = i + 1 To UBound(sLL)
If sLL(i) <> "" Then
MP1 = Mid(sLL(K), 1, InStr(1, sLL(K), "/") - 1)
MP2 = Mid(sLL(i), 1, InStr(1, sLL(i), "/") - 1)
If MP1 > MP2 Then
s5 = sLL(i)
sLL(i) = sLL(K)
sLL(K) = s5
End If
End If
Next
Next
ss = ""
For i = UBound(sLL) To 0 Step -1
For K = i - 1 To 0 Step -1
If sLL(K) = sLL(i) Then
sLL(i) = ""
ss = ss & "," & sLL(i)
End If
Next
Next
For i = 0 To UBound(sLL)
If sLL(i) <> "" And K < 5 Then
List1.AddItem Replace(sLL(i), "/", "次:"), List1.ListCount
End If
Next
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
'注意text1 用控件数组text1 (1) 到text1 (16)
dim i% , j% ,t% , A%(0 to 9) , S$( 0 to 9 )
for i= 1 to 16
A( val( text1(i) ) )= A( val( text1(i) ) )+1
next
list1.clear
for i= 0 to 9
list1.AddItem i & "出现" & A( i ) & " 次 "
next
dim i% , j% ,t% , A%(0 to 9) , S$( 0 to 9 )
for i= 1 to 16
A( val( text1(i) ) )= A( val( text1(i) ) )+1
next
list1.clear
for i= 0 to 9
list1.AddItem i & "出现" & A( i ) & " 次 "
next
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询