下面是一段产生n阶魔方阵的代码,运行时下界越标,红色部分有问题
但是本人愚钝,实在不知道如何改动?请赐教!!
Private Sub Command1_Click()
Dim k%, i%, j%, m() As Integer
n = Val(Text1.Text)
i = 1
j = n / 2 + 1
ReDim m(1 To n, 1 To n)
For k = 1 To n * n
m(i, j) = k
If (k Mod n = 0) Then
i = i + 1
ElseIf i = 1 Then
i = n: j = j + 1
ElseIf j = n Then
j = 1: i = i - 1
Else
i = i - 1: j = j - 1
End If
Next k
For i = 1 To n
For j = 1 To n
Picture1.Print m(i, j); Tab(j * 5)
Next j
Picture1.Print
Next i
End Sub