这是一个过于简单的例子,但我已经伤透了时间。将其放入模块--
- Type TStrArray
- Items() As String
- End Type
- Sub Test()
- Dim jagged() As TStrArray
-
- [color=green] '' add the first "record"[/color]
-
- ReDim jagged(0)
-
- [color=green] '' add a "field"[/color]
-
- ReDim jagged(0).Items(0)
-
- [color=green] '' populate it[/color]
-
- jagged(0).Items(0) = "Drawing1"
-
- [color=green] '' oh my, we just discovered we have a layout, we need another "field"[/color]
-
- ReDim Preserve jagged(0).Items(1)
-
- [color=green] '' ok, populate it[/color]
-
- jagged(0).Items(1) = "Layout2"
- [color=green] '' oh my, and yet another layout[/color]
-
- ReDim Preserve jagged(0).Items(2)
-
- [color=green] '' populate it[/color]
-
- jagged(0).Items(2) = "Layout3"
-
- [color=green] '' ok, let's add another "record"[/color]
-
- ReDim Preserve jagged(1)
-
- [color=green] '' add 4 "fields" to this record (remember that basic is
- '' goofy, dim (3) = elements 0,1,2,3 so 4 elements total[/color]
-
- 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"
-
- [color=green] '' 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.[/color]
-
- End Sub
|