Solved

Collections

Posted on 2000-03-06
7
338 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
ID: 2588965
Can you paste the exact code here that didn't work?

Wes
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2590192
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
ID: 2594949
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:jjjjjjj
ID: 2597702
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
ID: 2597703
This question has a deletion request Pending
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2597889
This question no longer is pending deletion
0
 
LVL 14

Accepted Solution

by:
wsh2 earned 50 total points
ID: 2597890
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

828 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