VB 关于Collection Add添加 自定义的数据类型(Type)的问题
OptionExplicitPrivateSchoolAsNewCollectionPrivateTypeStudentNameAsStringAgeAsIntegerN...
Option Explicit
Private School As New Collection
Private Type Student
Name As String
Age As Integer
Num As Integer
End Type
Private Sub Command1_Click()
Dim kk As Student, sbsb
kk.Name = "张三"
kk.Age = 20
kk.Num = 1
School.Add kk, kk.Num
End Sub
我想把Student 自定义数据类型 Add 到 School 里,可是老提示出错,这个提示迷迷糊糊的。
编译错误:
只有定义在公共对象模块中用户定义类型能和变体类型相互转换或传递给后期绑定功能。 展开
Private School As New Collection
Private Type Student
Name As String
Age As Integer
Num As Integer
End Type
Private Sub Command1_Click()
Dim kk As Student, sbsb
kk.Name = "张三"
kk.Age = 20
kk.Num = 1
School.Add kk, kk.Num
End Sub
我想把Student 自定义数据类型 Add 到 School 里,可是老提示出错,这个提示迷迷糊糊的。
编译错误:
只有定义在公共对象模块中用户定义类型能和变体类型相互转换或传递给后期绑定功能。 展开
2个回答
展开全部
为了大家进步,我觉得有必要把更多的选择告诉大家。
http://bbs.csdn.net/topics/10061465
http://bbs.csdn.net/topics/10061465
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private school As List(Of student) = New List(Of student)
Private Structure student
Dim name As String
Dim age As Integer
Dim num As Integer
End Structure
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s As New student
With s
.name = "tom"
.age = 20
.num = 10
End With
school.Add(s)
End Sub
忘了说了这个是vb.net的。
Private Structure student
Dim name As String
Dim age As Integer
Dim num As Integer
End Structure
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s As New student
With s
.name = "tom"
.age = 20
.num = 10
End With
school.Add(s)
End Sub
忘了说了这个是vb.net的。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询