当前位置:编程学习 > VB >>

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 --------------------编程问答--------------------
引用 3 楼 king06 的回复:
Set myclass = Nothing
  SearchSet.MoveNext

上面是个好办法! --------------------编程问答--------------------
引用 4 楼 lyserver 的回复:
引用 3 楼 king06 的回复:
Set myclass = Nothing
SearchSet.MoveNext

上面是个好办法!

2F写法习惯好,阐述清晰~
居然得江南兄称道
--------------------编程问答-------------------- 偶搬个小板凳,听课来的……
补充:VB ,  基础类
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,