with给对象赋值问题
如下代码:
Do While Not SearchSet.EOF
Dim myclass As New ListType
With myclass
.Id = CInt(SearchSet!Id)
.TypeName = CStr(SearchSet!TypeName)
End With
collect.Add myclass, CStr(SearchSet!Id)
SearchSet.MoveNext
Loop
collect 是一个 Collection对象, ListType是个类,内容为以下:
Public Id As Integer
Public TypeName As String
问题是:
再循环赋值时,循环添加到collect 的值都是最后一个值了,跟踪发现,
Dim myclass As New ListType 新new出来的对象赋值全都变了
貌似并没有new出来新的对象。
如何解决呢?
--------------------编程问答-------------------- Dim myclass As New ListType
移开 --------------------编程问答-------------------- --------------------编程问答-------------------- Set myclass = Nothing
SearchSet.MoveNext --------------------编程问答--------------------
上面是个好办法! --------------------编程问答--------------------
2F写法习惯好,阐述清晰~
居然得江南兄称道
--------------------编程问答-------------------- 偶搬个小板凳,听课来的……
补充:VB , 基础类