我已经声明了一个UDT,我需要初始化一个包含UDT特定记录的数组,我该如何在模块级别进行。
这是我尝试过的
Public Type MyType
id As Integer
name As String
values As Double
End Type
private MY_TYPES(1) As MyType
My_TYPES(0) = newMyType(1, "Item 1", 15.9)
My_TYPES(1) = newMyType(2, "Item 2", 30.2)
Private Function newMyType(byval id as Integer, byval name as String, _
byval v as Double) As MyType
Dim t As MyType
t.id = id
t.name = name
t.value = v
newMyType = t
End Function
我得到的错误是Invalid outside procedure
正如你所看到的,我尝试重现像Collection
或List
Set
静态初始化
我想把这个集合公开为常数,我怎么能实现这个呢?
答案 0 :(得分:3)
你必须在sub中放置以下2行,然后调用sub来初始化udt
My_TYPES(0) = newMyType(1, "Item 1", 15.9)
My_TYPES(1) = newMyType(2, "Item 2", 30.2)
或者您可以将这两行放在if..then中的工作子中,并使用模块级init boolean