VB帮忙检查关于统计数字次数的代码错在那里?(刚学VB)

例如文本框1内容为(multiline=true)12,17,19,22,23,29,30,34,02,10,15,19,03,05,17,30,40,42,13,18,... 例如文本框1内容为(multiline=true)
12,17,19,22,23,29,30,34,
02,10,15,19,
03,05,17,30,40,42,
13,18,24,36,38,42,20,31,45,
02,05,15,
07,16,18,31,36,41,11,14,39,46,
01,06,

怎样统计次数?象这样.

出现0次 04,08,09,21,25,26,27,28,32,33,35,37,43,44,47,48,49, =17个
出现1次 01,03,06,07,10,11,12,13,14,16,20,22,23,24,29,34,38,39,40,41,45,46, =22个
出现2次 02,05,15,17,18,19,30,31,36,42, =10个.
问题补充:最大不超过99,最小1

代码
'设文本框1内容为str
Sub Test(str as string) ' 这句为什么不用command click
dim A() as string
Arr=Split(str,",")

dim B(99) as integer
dim i as integer
for i=lbound(A) to ubound(A)
B(int(A(i))=B(int(A(i))+1 "显示是红色的
next i
for i=0 to 99
debug.print B(i)
next i
end sub
展开
 我来答
33499731
2006-11-30 · TA获得超过371个赞
知道答主
回答量:230
采纳率:0%
帮助的人:205万
展开全部
Sub Test(str as string) ' 定义了一个子程序,可以供程序调用,可以在其他事件里用CALL TEST(参数)来调用该子程序
dim A() as string
Arr=Split(str,",") '这里应该为A吧~~

dim B(99) as integer
dim i as integer
for i=lbound(A) to ubound(A)
B(int(A(i))=B(int(A(i))+1 '这句错得太离谱了,如果A(I)为13的话,这句的意思相当于B(13)=B(13+1),而且少了一个括号~~
next i
for i=0 to 99
debug.print B(i)
next i
end sub

先在窗体上画一个按纽,然后把代码复制到代码窗口里,完整的程序:
Private Sub Command1_Click()
Dim k As String
k= "1,333,4,239,93,92,323,333,333,123,33,11,23,123,1,45,34,12,3,123,231,23,51,23,123"
Call Test(k)
End Sub

Sub Test(str As String) ' 创建一个子程序TEST
Dim A() As String '定义一个空的数组
A = Split(str, ",") '字符中以","为分界符把数值赋予数组A
Dim B() As Integer '定义一个空数组
Dim i As Integer
For i = LBound(A) To UBound(A)
ReDim Preserve B(i) '重新定义数组B,并保留B中的植
B(i) = Int(A(i)) '把A中的字符转化为整数赋予B
Next i
For i = LBound(B) To UBound(B)
Print B(i)
Next i
'以下开始是计算出现的次数
Dim c() As String, j, l, o, q, tem() As Integer
ReDim c(UBound(B))
q = 0
For i = 0 To UBound(B)
For j = 0 To UBound(B)
If B(i) = B(j) Then '循环判断当前数出现的次数
l = l + 1 '记录它出现的次数
End If
Next j
ReDim Preserve tem(i) 'TEM用来记录已经判断过的数
tem(i) = B(i)
For q = 0 To UBound(tem) '循环判断该数是否重复判断过
If tem(q) = B(i) Then
o = o + 1
End If
Next
If o = 1 Then '如果不是重复判断就把它保存起来
c(l) = c(l) & B(i) & " "
End If
o = 0
l = 0
Next i
For i = 0 To UBound(c)
If c(i) <> "" Then
Print "出现过" & i & "次的有:" & c(i) '输出
End If
Next
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式