需求
一组数据,分别有 name,age,height等属性
public type mytype
name As String
age As Integer
height As Single
end type想通过name快速访问某个数据,于是想把数据添加到集合中,但是编译出错,提示
dim a1 as mytype
a1.name="helloworld"
age=30
height=1.8 Dim collxx As Collection
这个地方就出错了,按照集合定义,集合可以是任意数据类型或者对象,但是为什么不成功呢?
collxx.Add a1, "helloworld"
提示
---------------------------
Microsoft Visual Basic
---------------------------
编译错误:只有定义在公共对象模块中用户定义类型能和变体类型相互转换或传递给后期绑定功能。
---------------------------
确定 帮助
---------------------------
一组数据,分别有 name,age,height等属性
public type mytype
name As String
age As Integer
height As Single
end type想通过name快速访问某个数据,于是想把数据添加到集合中,但是编译出错,提示
dim a1 as mytype
a1.name="helloworld"
age=30
height=1.8 Dim collxx As Collection
这个地方就出错了,按照集合定义,集合可以是任意数据类型或者对象,但是为什么不成功呢?
collxx.Add a1, "helloworld"
提示
---------------------------
Microsoft Visual Basic
---------------------------
编译错误:只有定义在公共对象模块中用户定义类型能和变体类型相互转换或传递给后期绑定功能。
---------------------------
确定 帮助
---------------------------
集合类?没明白 vb6好像没有class关键字,我回去看看
public name As String
public age As Integer
public height As Single
保存。删除那个 type 的。再使用看看。
如果你就是想做一个对象,对象中就包含这些属性,那用类模块;如果你想做一个控件,控件的属性是这些,那就用UserControl设计器(自定义控件设计器,ActiveX 控件 工程);或是其他。
再将自己的意图认真补充一下吧。
添加collection.add item,item.name
后直接使用
collection.item("hello").age获得改对象的age数据
如果是用数组的话只能for 循环,查找到name=hello,然后再提取这个元素的age数据
不想太多的使用循环~