|
本帖最后由 rkexy 于 2017-12-15 10:36 编辑
- <div class="blockcode"><blockquote>'初始化空间为 10
- Private Sub Class_Initialize()
- ReDim m_datas(1 To init_space)
- Dim i As Integer
- For i = 1 To init_space Step 1
- '无论何时,对象之间赋值需要 Set 关键字
- Set m_datas(i) = Nothing
- Next
- m_length = 0
- m_useable_length = init_space
- m_element_type = ""
- End Sub
- Private Sub Class_Terminate()
- 'Erase m_datas '这句崩了,下面两句没问题
- Call Clean
- ReDim m_datas(0)
- End Sub
- '清除所有数据
- Public Function Clean()
- Dim i As Long
- For i = 1 To m_length
- Set m_datas(i) = Nothing
- Next
- End Function
复制代码
然后我在一个Sub中测试这个类- Sub test()
- Dim map As Object_vector
- Dim i As Long
- Dim each_tile As Coord
-
- Set map = New Object_vector
-
- For i = 1 To 3270 Step 1
- Set each_tile = New Coord
- each_tile.x = i
- each_tile.y = i
- each_tile.coord_type = NONE
-
- Call map.Insert(i, each_tile)
- Next
复制代码
为了把问题更全面,我把Coord类也贴出了,不过我认为和它没关系
- Public Enum ENUM_COORD_TYPE
- NONE = -1
- GROUND = 0
- WALL = 1
- End Enum
- Private m_x As Integer
- Private m_y As Integer
- Private m_coord_type As ENUM_COORD_TYPE '坐标类型
- Private Sub Class_Initialize()
- m_x = -1
- m_y = -1
- m_coord_type = NONE
- End Sub
- Private Sub Class_Terminate()
- m_x = -1
- m_y = -1
- m_coord_type = NONE
- End Sub
复制代码
|
VBA, Excel宏, 数组, Erase, VBA, Excel宏, VBA, Excel宏, VBA, Excel宏, VBA, Excel宏
|