Solved

Running old VB 6 collections in C#

Posted on 2003-11-07
7
250 Views
Last Modified: 2010-04-16
Hi,
I want to loop around an old VB 6 collection using C#.  The VB collection comes from a dll.

The old VB code that wrote out the collection looked like this:
'********************************************************************
     Dim User, Users
     Set Users = Users.displayList(arg1, arg2, arg3)          'Call the COM object, pass in parameters
     For Each User in Users                                             'Loop around the collection and print
             Response.Write User.firstName
     Next
********************************************************************
I have referenced the dll inside ASP.Net and can create the object, but how do I return the collection and loop around to print out its values?

AD.Users users = new AD.UsersClass();
AD.User user = new AD.UserClass();
// A bit lost now ???????????????????????

0
Comment
Question by:Hob_Nob
  • 4
  • 3
7 Comments
 
LVL 2

Expert Comment

by:sedmans
ID: 9700961
You have got a foreach statement in C# as well.

The syntax is

foreach (AD.User user in Users)
{
// work with the items.
}
0
 

Author Comment

by:Hob_Nob
ID: 9701366
Cheers sedmans, but before I can loop around the collection, I need to call a function inside the dll that builds the collection according to the arguments passed in.  The same function returns a collection object of users, which I can then print out:

In VB I would use the SET statement:
'*********************************
Set Users = Users.displayList(arg1, arg2, arg3)
For Each User In Users...
*********************************

How do I call the function 'displayList' in class 'Users', pass a collection back and loop around it?  



0
 
LVL 2

Expert Comment

by:sedmans
ID: 9701442
If the dll is an ActiveX dll then you need to do is add a reference to the dll and then you have access to it.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

 

Author Comment

by:Hob_Nob
ID: 9701529
I have a reference to it, and with Intellisense, I can see my 'displaylist' function, I know it is referenced.  I can't loop around my collection until I call the function 'displaylist' inside the 'Users' class.  

Would the code look anything like this:

AD.User user = new AD.User();
AD.Users users = new AD.Users();
foreach (AD.User user in Users.displayList(arg1, arg2, arg3))
{
// work with the items.
}

Or how do I return the Users collection to a variable in C# so I can then loop around it?
0
 
LVL 2

Expert Comment

by:sedmans
ID: 9702029
Try,

AD.User user = new AD.User();
AD.Users users = Users.displayList(arg1, arg2, arg3);
foreach (AD.User user in users)
{
// work with the items.
}
0
 
LVL 2

Accepted Solution

by:
sedmans earned 150 total points
ID: 9702040
forget my last post.  It has been a long day!

try

AD.User user = new AD.User();
AD.Users users = new AD.Users();
foreach (AD.User user in users.displayList(arg1, arg2, arg3))
{
// work with the items.
}
0
 

Author Comment

by:Hob_Nob
ID: 9714475
My code was a bit of a variation on your answer, but basically correct. Thanks alot
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

790 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