gpt4 book ai didi

arrays - VBA - MsgBox 二维数组(矩阵)

转载 作者:行者123 更新时间:2023-12-02 12:58:49 29 4
gpt4 key购买 nike

我正在尝试使用 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

这是我得到的结果:

enter image description here

最佳答案

您已互换了 wh

Dim msg As String

For i = 0 To h
For ii = 0 To w
msg = msg & arr(i, ii) & vbTab
Next ii
msg = msg & vbCrLf
Next i

MsgBox msg

关于arrays - VBA - MsgBox 二维数组(矩阵),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41852985/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com