作业帮 > 综合 > 作业

vb程序Dim a(1 To 20) As Integer,i As Integer,j As Integer

来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/11 04:13:35
vb程序Dim a(1 To 20) As Integer,i As Integer,j As Integer
Dim a(1 To 20) As Integer,i As Integer,j As Integer
Private Sub Command1_Click()
Dim a(1 To 20) As Integer
For j = 1 To 2
For i = 1 To 10
a(i) = Int(Rnd * 21) + 20
Text1 = Text1 & Str(a(i))
Next i
Text1 = Text1 & vbCrLf
Next j
End Sub
Private Sub Command2_Click()
Dim b(20 To 40) As Integer
a(i) = Int(Rnd * 21) + 20
b(a(i)) = 0
For i = 1 To 20
b(a(i)) = b(a(i)) + 1
Text2 = b(a(i)) & vbCrLf
Next i
End Sub
为什么数组越界 哪出错啦
这个 程序要实现的是 产生20个20—40间的两位随机数 统计不同数据出现的次数
vb程序Dim a(1 To 20) As Integer,i As Integer,j As Integer
在 Command2_Click() 中
你还有没有定义i,就开始使用a(i)了
而且没有定义的变量初始值是0
而你的a是1 到20 的,根本就没有0