使用具有手动大小管理的阵列,以及自我管理其大小的其他数据结构

时间:2018-05-24 11:09:43

标签: vba

VBA允许定义动态可调整大小的数组:

Dim s() As String
For i = 0 To ... 'some end condition
    Redim Preserve s(i)
    s(i) = 'fill with some value
Next

这很容易出错。还有其他自动调整大小的集合,例如VBA Collection

Dim col As New Collection
For i = 0 To ... 'some end condition
    s.Add 'fill with some value
Next

Scripting.Dictionary(提及 Microsoft Scripting Runtime ):

Dim dict As New Scripting.Dictionary
For i = 0 To ... 'some end condition
    s.Add i, 'fill with some value
Next

ArrayList(引用 mscorlib ):

Dim al As New ArrayList
For i = 0 To ... 'some end condition
    al.Add 'fill with some value
Next

手动管理阵列的大小有什么实际的 1 好处?

1。据推测,它会对嵌入式编程或某些需要接近金属性能的游戏引擎产生影响;但是如果你为此目的使用VBA,那么你应得的。

0 个答案:

没有答案