本文介绍了如何在列表中添加结构类型对象或从列表中检索结构类型对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在列表中添加结构类型对象或从列表中检索结构类型对象.只有最后写入的值似乎是可检索的. VS2005中的部分样本.实验代码,仅检索最后写入的值.

How do I add and retrieve a structure type object to/from a list. Only the last value written seems to be retrieveable. Partial sample in VS2005. Experimental code which only retrieves the last value written.

While (Not datainfile.EndOfStream And i < pk_size)
 With pk_set
  .profile = datainfile.ReadLine '.profile = code(datainfile.ReadLine, myPWD)
  .UID = datainfile.ReadLine '.UID = code(datainfile.ReadLine, myPWD)
  .PWD = datainfile.ReadLine '.PWD = code(datainfile.ReadLine, myPWD)
  .URL = datainfile.ReadLine '.URL = code(datainfile.ReadLine, myPWD)
  j = lstprofiles.Items.Add(.profile) 'profileIdx.Add(.profile) <-- not needed?
  End With
  pkList.Add(pk_set) '<-----<<this increment isn't occurring
  With pkList(i)
  MsgBox("wrote to pkList: index = " & j & ", " & _
                           "count = " & pkList.Count & ", " & _
                            .profile & ", " & .UID & ", " & .PWD & ", " & .URL)
 End With

 ''''With lstprofiles.Items(j) 'was first i-1 then i
 '''' Dim lItemToString As String = .ToString
 '''' MsgBox("read from lstprofiles: index = " & j & ", " & _
 ''''                            lItemToString & " AKA " & lstprofiles.Items(j))
 ''''End With
 i += 1
End While

For i = 0 To 8 'This iterated
 ''''With lstprofiles.Items(i) 'was i-1
 '''' Dim lItemToString As String = .ToString
 '''' MsgBox("read from lstProfiles: position index = " & i & ", |" & lItemToString & "|")
 ''''End With
 ''''MsgBox("lstProfiles.items(" & i & ") = " & lstprofiles.Items(i))
'With pkList(i) ''With pkList.Item(i + 1)
 MsgBox("pkList(" & i & ") = " & pkList(i).ToString & _
        " Profile = " & pkList(i).profile & _
        " UID = " & pkList(i).UID & _
        " PWD = " & pkList(i).PWD & _
        " URL = " & pkList(i).URL)
'End With

Next



For Each pkpr_set In pkList 'this contains the object's last value only,
                            'for all values of each
 With pkpr_set
 MsgBox("pkpr's profile is " & .profile & " and it contains " _
                      & .UID & ", " _
                      & .PWD & ", " _
                      & .URL)
 End With
Next

推荐答案

pk_set = New <whatever type pk_set is>()


这篇关于如何在列表中添加结构类型对象或从列表中检索结构类型对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 02:36