我想使用MsgBox可视化二维矩阵(数组),但我有的代码并没有给我正确的表示。VBA - MsgBox一个二维数组(矩阵)
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'长度的限制(所以它的跳跃或东西)。你可以尝试将每一行保存在一个字符串中,这样你就可以得到一个'String'数组,然后在一个'MsgBox'中循环并显示它们。 –
对于我真的很喜欢试图看到以可视方式输出数组。 –
@DougCoats只有你答应+1 :) –