【发布时间】:2018-02-15 09:50:18
【问题描述】:
我有一个在子例程中声明的数组。我希望它充满两个值。一个用于单元格列表的每个坐标。我知道这并不总是最好的方法,但是由于涉及我程序的其余部分的原因,我需要完全这样做。
'This sub contains more, I've just included only the relevant stuff
Sub Start_Click()
Dim arTime() As Integer
arTime = FillTimeArray(arTime)
End Sub
'This is used to fill the array with a list of 12 columns that are 24 rows long
'They are offsetted intentionally
Function FillSpotArray(ByRef arr() As Integer) As Integer()
For j = 0 To 11
For i = 0 To 23
arr(i, j) = Format(i + 2, j + 1)
Next i
Next j
End Function
【问题讨论】:
-
您的函数名为
FillSpotArray,但在您的测试 Sub 中,您调用的是FillTimeArray... -
我希望它填充两个值。一个用于单元格列表的每个坐标这是否意味着恰好有 2 个值,或者每个坐标有 2 个值?此外,
Format(i + 2, j + 1)只能是错误的 =>Format(0 + 2, 0 + 1) = Format(2, 1)和1不是有效格式...请确保您知道Format()在做什么。 (您可能正在寻找Array(i + 2, j + 1)...)