Solved

Running old VB 6 collections in C#

Posted on 2003-11-07
7
243 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

778 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