Solved

Collections

Posted on 2000-03-06
7
318 Views
Last Modified: 2010-05-02
Why can't a programmer add more than one occurance of an object to a collection in the same procedure, ie..  while processing result sets, Vb6 would not add the correct result set field data to the collection in the same procedure.  I had to create an add sub procedure and pass it the record in order to have it added to the collection properly.  Listed below is an example:

This did not work properly:

While RDORS not EOF

 move RSFields to object fields
 Add to collection
 RS.Movenext

Wend

This did work:

While RDORS not EOF

 Call subprocedure passing RDORS object
 (subprocedure add to collection)
 RS.Movenext

Wend


TIA,
jjjjjjj














0
Comment
Question by:jjjjjjj
7 Comments
 
LVL 4

Expert Comment

by:wesleystewart
Comment Utility
Can you paste the exact code here that didn't work?

Wes
0
 
LVL 14

Expert Comment

by:wsh2
Comment Utility
What it looks like to me, is that in the first case (the one that didn't work).. you did not create a collection object before hand.. and that in the second case (the procedure).. you probably did.

Try this code out (I am using a Listview collection as an example)

Dim itmWork as Listitem

While RDORS not EOF

  ' Create collection object
  Set itmWork = lvwListview.ListItems.Add()

  ' Move fields
  With itmWork
    .Key = Rs.Key    
    .SmallIcon = NameOfPicture
    .Text = Rs.Text
    .subitems(1) = Rs.Field1
    .subitems(2) = Rs.Field2
    .subitems(3) = Rs.Field3
  End With

  ' Get Next Record
  RS.Movenext

Wend


0
 
LVL 4

Expert Comment

by:TigerZhao
Comment Utility
follow code did not work

Dim o as New Collection
'...
o.Add rs!Field1
'...
rs.Close
'...
debug.print o(I)

Because you add the Field OBJECT to the collection, after recordset close, the field object cann't access, the right way is:

o.Add rs!Field1.Value
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 1

Author Comment

by:jjjjjjj
Comment Utility
I am deleting because I have solved the issue separately, without using any of the comments.

The reason why it does not work is due to scope.  I have resolved by re-establishing the proper scope.

jjjjjjj
0
 
LVL 1

Author Comment

by:jjjjjjj
Comment Utility
This question has a deletion request Pending
0
 
LVL 14

Expert Comment

by:wsh2
Comment Utility
This question no longer is pending deletion
0
 
LVL 14

Accepted Solution

by:
wsh2 earned 50 total points
Comment Utility
from my earlier comment.. << you did not create a collection object before hand.. and that in the second case (the procedure).. you probably did >>

Scope is everything.. <smile>

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now