vb编程的问题 说的a(i) = int(rnd*90)+10下标越界

来源:百度知道 编辑:UC知道 时间:2024/06/22 13:32:53
Dim a() As Integer

Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = "最大值"
Text5.Text = "最小值"
Text5.Text = "平均值"
Command1.Caption = "重置"
Command2.Caption = "计算"
Command3.Caption = "关闭"
Dim p As String
p = ""
For i = 1 To 10
a(i) = Int(Rnd * 90) + 10
p = p & Str(a(i)) & ","
Next
Text7.Text = p
End Sub

第一句 声明数组要写上下界,下界是0可省,你可以写成如下形式:

Dim a(1 To 10) As Integer

Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = "最大值"
Text5.Text = "最小值"
Text6.Text = "平均值"
Command1.Caption = "重置"
Command2.Caption = "计算"
Command3.Caption = "关闭"
Dim p As String
p = ""
For i = 1 To 10
a(i) = Int(Rnd * 90) + 10
p = p & Str(a(i)) & ","
Next
Text7.Text = p
End Sub

这样程序就不会出错了!