运行代码:
Dim myarray(1 To 5, 1 To 5) As Long
Private Sub Command1_Click()
Print " 转换前的矩阵"
For intx = 1 To 5
For inty = 1 To 5
myarray(intx, inty) = intx * 10 + inty
Next
Next
For intx = 1 To 5
For inty = 1 To 5
Print myarray(intx, inty),
Next inty
Next intx
Print vbCrLf
End Sub
Private Sub Command2_Click()
Print " 转换后的矩阵"
For intx = 1 To 5
For inty = intx To 5 '每次交换只能从intx开始,不然重复交换,就和原来的一样了。
temp = myarray(intx, inty)
myarray(intx, inty) = myarray(inty, intx)
myarray(inty, intx) = temp
Next inty
Next intx
For intx = 1 To 5
For inty = 1 To 5
Print myarray(intx, inty),
Next inty
Next intx
End Sub
学习总结:
1、每次交换只能从行坐标intx开始,不然重复交换,就和原来的一样了。