下面VB语句为什么会显示下标越界?
发布网友
发布时间:2024-10-24 07:04
我来回答
共1个回答
热心网友
时间:2024-10-24 20:30
你标错了。
Private Sub Command1_Click()
Dim a(4, 5) As Integer, i As Integer, j As Integer, x%, y%
Picture1.Cls
For i = 1 To 4
For j = 1 To 5
a(i, j) = Int(Rnd * 90) + 10
Next
Picture1.Print a(i, j); 《——实际是这里下标越界。因为内层For循环结束时,j的值为6。
Next
Picture1.Print
If a(x, y) = a(1, 1) Then
For i = 1 To 4
For j = 1 To 5
If a(i, j) > a(x, y) Then a(x, y) = a(i, j)
Next j
Next i
End If
Picture1.Print "数组中最大元素为第" & i & "行" & "第" & j; "列的" & a(x, y)
End Sub