Private Sub Command1_Click()
Dim a(20, 20) As Integer
n = CInt(InputBox("N="))
i = 1: j = 1: k = 1: l = n - 1
Do While l > 0
For t = 1 To l: a(i, j) = k: k = k + 1: j = j + 1: Next t
For t = 1 To l: a(i, j) = k: k = k + 1: i = i + 1: Next t
For t = 1 To l: a(i, j) = k: k = k + 1: j = j - 1: Next t
For t = 1 To l: a(i, j) = k: k = k + 1: i = i - 1: Next t
i = i + 1: j = j + 1: l = l - 2
Loop
If n Mod 2 = 1 Then a(i, j) = k
For i = 1 To n
For j = 1 To n
Print Format(a(i, j), "@@@@");
Next j
Next i
End Sub