为什么当我运行下面这个程序时会出现“下标越界这个问题”? 20
Dima()AsIntegerDimnAsInteger,kAsInteger,iAsInteger,jAsIntegerPrivateSubForm_Activate(...
Dim a() As Integer
Dim n As Integer, k As Integer, i As Integer, j As Integer
Private Sub Form_Activate()
ReDim a(n, n)
n = Val(Text1.Text)
k = (n + 1) / 2
a(1, k) = 1
j = 1
For i = 2 To n * n
j = j - 1
If j < 1 Then j = n
k = k + 1
If k > n Then k = 1
If a(j, k) <> 0 Then
j = j + 1
If j > n Then j = 1
j = j + 1
If j > n Then j = 1
k = k - 1
If k < 1 Then k = n
End If
a(j, k) = i
Picture1.Cls
Next i
For i = 1 To n
For j = 1 To n
Picture1.Print a(i, j) & Space(5);
Next j
Picture1.Print
Next i
End Sub 展开
Dim n As Integer, k As Integer, i As Integer, j As Integer
Private Sub Form_Activate()
ReDim a(n, n)
n = Val(Text1.Text)
k = (n + 1) / 2
a(1, k) = 1
j = 1
For i = 2 To n * n
j = j - 1
If j < 1 Then j = n
k = k + 1
If k > n Then k = 1
If a(j, k) <> 0 Then
j = j + 1
If j > n Then j = 1
j = j + 1
If j > n Then j = 1
k = k - 1
If k < 1 Then k = n
End If
a(j, k) = i
Picture1.Cls
Next i
For i = 1 To n
For j = 1 To n
Picture1.Print a(i, j) & Space(5);
Next j
Picture1.Print
Next i
End Sub 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询