How to edit an item in a VB6 collection

Could you tell me how to edit an item in the VB6 collection. ex I have the following collection -

Dim OrdLines As New Collection OrdLines.Add (111) OrdLines.Add (111) OrdLines.Add (222) OrdLines.Add (333) OrdLines.Add (444) 

Now my requirement is to edit element 3 and want to change it, let it say “ABC”. How can i do this.

+6
source share
2 answers

You can get the objects by reference and change them:

SomeClass.cls

 Option Explicit Public Value As String 

Form1.frm

 Option Explicit Private Sub Form_Load() Dim Col As Collection Dim SC As SomeClass Set Col = New Collection Set SC = New SomeClass SC.Value = "hello" Col.Add SC Set SC = New SomeClass SC.Value = "world" Col.Add SC MsgBox Col(2).Value Col(2).Value = "cruel word" MsgBox Col(2).Value End Sub 
+9
source

I think you can’t. You must delete the item and re-add the modified item.

+8
source

Source: https://habr.com/ru/post/893352/


All Articles