【发布时间】:2017-01-25 13:34:02
【问题描述】:
我正在尝试使用 MsgBox 可视化 2D 矩阵(数组),但我的代码没有给我正确的表示。
Sub test()
Dim M(22, 7) As Double
TwoD_Array_Matrix_In_MSGBOX (M)
End Sub
'_________________________________________________________________________
Public Function TwoD_Array_Matrix_In_MSGBOX(arr As Variant)
h = UBound(arr, 1)
w = UBound(arr, 2)
'MsgBox ("h = " & CStr(h + 1) & vbCrLf & "w = " & CStr(w + 1)) ' to check if the width and hight of the Matrix are correct
Dim msg As String
For i = 0 To w
For ii = 0 To h
msg = msg & arr(ii, i) & vbTab
Next ii
msg = msg & vbCrLf
Next i
MsgBox msg
End Function
这是我得到的结果:
【问题讨论】:
-
我认为这是因为您受到
msg长度的限制(所以它正在跳过或其他东西)。您可以尝试将每一行保存在一个字符串中,这样您将拥有一个Strings 数组,然后循环并在MsgBox中显示它们 -
对于它的价值,我真的很喜欢尝试直观地查看数组输出的想法。
-
@DougCoats 仅在您承诺 +1 的情况下 :)
-
@ShaiRado 我做到了