Solved

How to edit collection variable in VB6 ?

Posted on 2010-11-12
5
843 Views
Last Modified: 2012-05-10
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 ?
0
Comment
Question by:dvplayltd
  • 3
5 Comments
 
LVL 7

Expert Comment

by:rogerard
ID: 34120626
You need to reference as

cAppSet.Item(sAPP_HARMONY) = 0
0
 
LVL 7

Expert Comment

by:rogerard
ID: 34120638
I believe you might also be able to reference it:
cAppSet.Item!sAPP_HARMONY = 0
0
 
LVL 7

Expert Comment

by:rogerard
ID: 34120641
Sorry, this
cAppSet!sAPP_HARMONY = 0
0
 
LVL 22

Accepted Solution

by:
danaseaman earned 500 total points
ID: 34120724
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
 

Author Closing Comment

by:dvplayltd
ID: 34120828
10x. I know Dictinary object from C# and I'm glad it is present in VB6. Thanks !
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question