0
我已經聲明瞭一個UDT,並且我需要初始化一個具有UDT特定記錄的數組,我將如何在模塊級別執行該操作。在VB6中初始化一個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
正如你可以看到它我試圖重現這將是一個java Collection
的靜態初始化像List
或錯誤Set
我想公開收集爲常量,我怎麼能實現這個?
您分配給My_TYPES陣列的兩行不能在過程外寫入。它們必須位於像newMyType函數那樣的函數/子/屬性中。 –