473,413 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

Passing various class types as parameters

Hi

I have the following code;

Public DA(3) As Object

DA(1) = New Class1
DA(2) = New Class2

Is there a way to pass the class types as parameter to a sub as below;

SetDA(Class1,1)
SetDA(Class2,2)

where the sub declares variables for the passed class types, as below?

Sub SetDA(ByRef ClassType As Object, ByVal Subs As Long)
DA(Subs) = New ClassType
End Sub

Thanks

Regards

Jun 27 '08 #1
6 852
"John" <in**@nospam.infovis.co.ukschrieb
Hi

I have the following code;

Public DA(3) As Object

DA(1) = New Class1
DA(2) = New Class2

Is there a way to pass the class types as parameter to a sub as
below;

SetDA(Class1,1)
SetDA(Class2,2)

where the sub declares variables for the passed class types, as
below?

Sub SetDA(ByRef ClassType As Object, ByVal Subs As Long)
DA(Subs) = New ClassType
End Sub

Have a look at System.Activator.CreateInstance. But what are you trying
to do? Where does the type information come from at runtime? Often there
are better solutions.
Armin
Jun 27 '08 #2
Hi Armin

Thanks. Class1 & 2 are data adapters for different tables. I need an array
of data adapters so I can write some generic code once the array has been
created.

Thanks again.

Regards

"Armin Zingler" <az*******@freenet.dewrote in message
news:uP**************@TK2MSFTNGP05.phx.gbl...
"John" <in**@nospam.infovis.co.ukschrieb
>Hi

I have the following code;

Public DA(3) As Object

DA(1) = New Class1
DA(2) = New Class2

Is there a way to pass the class types as parameter to a sub as
below;

SetDA(Class1,1)
SetDA(Class2,2)

where the sub declares variables for the passed class types, as
below?

Sub SetDA(ByRef ClassType As Object, ByVal Subs As Long)
DA(Subs) = New ClassType
End Sub


Have a look at System.Activator.CreateInstance. But what are you trying
to do? Where does the type information come from at runtime? Often there
are better solutions.
Armin


Jun 27 '08 #3
"John" <in**@nospam.infovis.co.ukschrieb
Hi Armin

Thanks. Class1 & 2 are data adapters for different tables. I need an
array of data adapters so I can write some generic code once the
array has been created.

Thanks again.
You can declare the items As DataAdapter. Why don't you know the type of
the object to be created?
Armin

Jun 27 '08 #4
hmmm...didn't know DataAdapter was a type. Thanks.

Regards

"Armin Zingler" <az*******@freenet.dewrote in message
news:uY**************@TK2MSFTNGP04.phx.gbl...
"John" <in**@nospam.infovis.co.ukschrieb
>Hi Armin

Thanks. Class1 & 2 are data adapters for different tables. I need an
array of data adapters so I can write some generic code once the
array has been created.

Thanks again.

You can declare the items As DataAdapter. Why don't you know the type of
the object to be created?
Armin

Jun 27 '08 #5
Dim x as DataAdapter
x = MyTableDataAdapter

dose not work as MyTableDataAdapter can not be converted to DataAdapter

"Armin Zingler" <az*******@freenet.dewrote in message
news:uY**************@TK2MSFTNGP04.phx.gbl...
"John" <in**@nospam.infovis.co.ukschrieb
>Hi Armin

Thanks. Class1 & 2 are data adapters for different tables. I need an
array of data adapters so I can write some generic code once the
array has been created.

Thanks again.

You can declare the items As DataAdapter. Why don't you know the type of
the object to be created?
Armin

Jun 27 '08 #6
"John" <in**@nospam.infovis.co.ukschrieb
Dim x as DataAdapter
x = MyTableDataAdapter

dose not work as MyTableDataAdapter can not be converted to
DataAdapter
You wrote about "data adapters", not table adapters. Ok, Table adapters
are derived from Component but this doesn't help much. Once more the
question why you don't know the object type in advance, and where does
the data type come from at run time? The table adapters do not have
much in common because the (most) members are specific to the table.
What do you want to do with the TableAdatpers in the array?
Armin

Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: justanotherguy63 | last post by:
Hi, I am designing an application where to preserve the hierachy and for code substitability, I need to pass an array of derived class object in place of an array of base class object. Since I...
8
by: Dennis Myrén | last post by:
I have these tiny classes, implementing an interface through which their method Render ( CosWriter writer ) ; is called. Given a specific context, there are potentially a lot of such objects,...
6
by: Lenn | last post by:
Hi, Could someone clarify my confusion regarding passing reference types to a method with ref keyword and explain when it's practical to use it. It's my understanding that in .NET reference...
1
by: Darsin | last post by:
Hi all, I am a new programmer to C# and i am having a following problem. I want to make a single method which takes a variable length array and display it contents. i have defined the method as:...
12
by: scottt | last post by:
hi, I am having a little problem passing in reference of my calling class (in my ..exe)into a DLL. Both programs are C# and what I am trying to do is pass a reference to my one class into a DLL...
3
by: Ross McLean | last post by:
Hi all, I've been teaching myself C# for a new project at work. I have a bit of a background in c++ and java but never been what you could call a guru. I'm having some strange things happening...
11
by: Macca | last post by:
Hi, I'm writing an application that will pass a large amount of data between classes/functions. In C++ it was more efficient to send a pointer to the object, e.g structure rather than passing...
7
by: TS | last post by:
I was under the assumption that if you pass an object as a param to a method and inside that method this object is changed, the object will stay changed when returned from the method because the...
8
by: =?Utf-8?B?UmF2aQ==?= | last post by:
Hi, I'm trying to pass values of different data-types to a web-service. I thought it would be easier to box these values and pass them as a System.object parameter, like public void...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.