Vb6 未定义UDT的数组

Vb6 未定义UDT的数组,vb6,Vb6,在VB6中,我试图创建一个未定义UDT的数组。我解释自己。 假设我有3个UDT: Public Type Country Countryproperty1 as String Countryproperty2 as Date End type Public type City Cityproperty1 as String Cityproperty2 as Date End type Public type Street Streetproperty as string

在VB6中,我试图创建一个未定义UDT的数组。我解释自己。 假设我有3个UDT:

Public Type Country
  Countryproperty1 as String
  Countryproperty2 as Date
End type

Public type City
  Cityproperty1 as String
  Cityproperty2 as Date
End type

Public type Street
  Streetproperty as string 
  Streetproperty as date
End type
我如何声明一个数组来欢迎这些类型中的任何一种

非常感谢!
Pierrick

可以将UDT放入类型为
Variant
的数组中,但前提是UDT是在公共类模块中定义的

只能在其中一种ActiveX项目类型中定义公共类模块。因此,首先,如果您的项目属于“标准EXE”类型,请从“项目属性”对话框中将其更改为“ActiveX EXE”,并将启动模式更改为“独立”而不是“ActiveX组件”。(或者,添加ActiveX DLL/控件项目并从主项目中引用它。)

然后向项目中添加一个类模块,并将其“instanceing”属性设置为“1-Private”以外的任何属性。将UDT定义移动到此类模块中

现在,您可以将UDT放入任何类型的数组
Variant


另一种方法是将类型作为类模块而不是UDT来处理。这不需要ActiveX项目类型,因此它也可以从VBA或VB6的学习版中使用。在本例中,您将有3个类模块,每个UDT一个。删除
Public Type…
End Type
,并将类型字段作为类模块的
Public
字段。由于这些将是
对象
s,因此它们对UDT的处理方式非常不同。他们将使用
Set
进行分配,并使用
New
创建实例(例如,
Set c1=New Country
)。分配将分配对象而不克隆它们。本例中的数组类型为
对象

谢谢您的回答Boann。