Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Running old VB 6 collections in C#

Posted on 2003-11-07
7
Medium Priority
?
271 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 450 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

604 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