魔法 发表于 2008-2-12 09:02:43

这是一个过于简单的例子,但我已经伤透了时间。将其放入模块--
Type TStrArray
    Items() As String
End Type
Sub Test()
    Dim jagged() As TStrArray
   
    ''add the first "record"
   
    ReDim jagged(0)
   
    ''add a "field"
   
    ReDim jagged(0).Items(0)
   
    ''populate it
   
    jagged(0).Items(0) = "Drawing1"
   
    ''oh my, we just discovered we have a layout, we need another "field"
   
    ReDim Preserve jagged(0).Items(1)
   
    ''ok, populate it
   
    jagged(0).Items(1) = "Layout2"
    ''oh my, and yet another layout
   
    ReDim Preserve jagged(0).Items(2)
   
    ''populate it
   
    jagged(0).Items(2) = "Layout3"
   
    ''ok, let's add another "record"
   
    ReDim Preserve jagged(1)
   
    ''add 4 "fields" to this record (remember that basic is
    ''goofy, dim (3) = elements 0,1,2,3 so 4 elements total
   
    ReDim Preserve jagged(1).Items(3)
   
    jagged(1).Items(0) = "Drawing2"
    jagged(1).Items(1) = "Layout1"
    jagged(1).Items(2) = "Layout2"
    jagged(1).Items(3) = "Layout3"
   
    ''yada. Add debug.print statments to suit to illuminate the contents
   
    ''in practice one would try to know ahead of time the number
    ''of array elements required, for the primary and nested arrays.
    ''There's a significant performance hit every time you use redim
    ''preserve; use it only when absolutely necessary.
   
End Sub
页: 1 [2]
查看完整版本: 2D阵列帮助