473,671 Members | 2,224 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 860
"John" <in**@nospam.in fovis.co.ukschr ieb
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.Activato r.CreateInstanc e. 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*******@free net.dewrote in message
news:uP******** ******@TK2MSFTN GP05.phx.gbl...
"John" <in**@nospam.in fovis.co.ukschr ieb
>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.Activato r.CreateInstanc e. 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.in fovis.co.ukschr ieb
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*******@free net.dewrote in message
news:uY******** ******@TK2MSFTN GP04.phx.gbl...
"John" <in**@nospam.in fovis.co.ukschr ieb
>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 = MyTableDataAdap ter

dose not work as MyTableDataAdap ter can not be converted to DataAdapter

"Armin Zingler" <az*******@free net.dewrote in message
news:uY******** ******@TK2MSFTN GP04.phx.gbl...
"John" <in**@nospam.in fovis.co.ukschr ieb
>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.in fovis.co.ukschr ieb
Dim x as DataAdapter
x = MyTableDataAdap ter

dose not work as MyTableDataAdap ter 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
4794
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 am using vector class(STL), the compiler does not allow me to do this. I do realize there is a pitfall in this approach(size of arrays not matching etc), but I wonder how to get around this problem. I have a class hierachy with abstract base...
8
2114
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, each requiring a call to that method to fulfill their purpose. There could be 200, there could be more than 1000. That is a lot of references passed around. It feels heavy. Let us say i changed the signature of the interface method to:
6
2839
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 types hold a reference to an object as opposed to object data itself. So, when reference type parameter is passed into a method, a copy of objects reference is passed in, so called method can do whatever to "original" object and a caller will see...
1
3127
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: public void DisplayVals(params object objArray) { foreach (object o in objArray) Console.WriteLine(o.ToString()); }
12
3014
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 function. When I try and compile the DLL I get "The type or namespace name "MyForm" could not be found. I think I have to reference the class but since the DLL needs to be built before the EXE it looks like I have a chicken and egg type problem....
3
2100
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 when I pass a class as a parameter to a Windows Form. Basically, I have a class that has several fields, two of these fields are an instance of an inner class, the rest are basic value types (bool's in this case). I have a windows form, the...
11
4125
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 the actual structure itself. Is this true of C# also?
7
3298
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 object is a reference type? my code is not proving that. I have a web project i created from a web service that is my object: public class ExcelService : SoapHttpClientProtocol {
8
8895
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 webmethod1(object a) where a can be of type string, DateTime, float, etc..
0
8472
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8909
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8819
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8596
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7428
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6222
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2806
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2048
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.