How to edit collection variable in VB6 ?

Hi experts!


I’m using collection in VB6.
  Set cAppSet = New Collection

  cAppSet.Add 1, sAPP_HARMONY

But my question is how can I later correct value of this collection ?
I try with
cAppSet(sAPP_HARMONY) = 0

give error, then I try first to delete it and add again, it work, but when I try to access collection I get error.
cAppSet.Remove sAPP_HARMONY
  cAppSet.Add 1, sAPP_HARMONY

and when make
If cAppSet(sAPP_HARMONY) Then

I get error
Object is not longer valid

So – how can I edit collection value ?
dvplayltdAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
danaseamanConnect With a Mentor Commented:
Try using the Scripting Dictionary object which is editable.
Add reference to "Microsoft Scripting Runtime"
Option Explicit

Dim cAppSet          As Scripting.Dictionary
Const sAPP_HARMONY   As String = "AppHarmony"

Private Sub Form_Load()
Set cAppSet = New Scripting.Dictionary

  cAppSet.Add sAPP_HARMONY, 1
  Debug.Print cAppSet(sAPP_HARMONY)
  cAppSet(sAPP_HARMONY) = 3
  Debug.Print cAppSet(sAPP_HARMONY)
  
End Sub

Open in new window

0
 
rogerardCommented:
You need to reference as

cAppSet.Item(sAPP_HARMONY) = 0
0
 
rogerardCommented:
I believe you might also be able to reference it:
cAppSet.Item!sAPP_HARMONY = 0
0
 
rogerardCommented:
Sorry, this
cAppSet!sAPP_HARMONY = 0
0
 
dvplayltdAuthor Commented:
10x. I know Dictinary object from C# and I'm glad it is present in VB6. Thanks !
0
All Courses

From novice to tech pro — start learning today.