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

Re: Passing various class types as parameters by Armin

Armin
Tue May 06 19:04:14 CDT 2008

"John" <info@nospam.infovis.co.uk> schrieb
> 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



Re: Passing various class types as parameters by John

John
Tue May 06 19:19:46 CDT 2008

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.nospam@freenet.de> wrote in message
news:uPE31X9rIHA.1436@TK2MSFTNGP05.phx.gbl...
> "John" <info@nospam.infovis.co.uk> schrieb
>> 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
>
>



Re: Passing various class types as parameters by Armin

Armin
Tue May 06 19:29:35 CDT 2008

"John" <info@nospam.infovis.co.uk> schrieb
> 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


Re: Passing various class types as parameters by John

John
Tue May 06 19:34:59 CDT 2008

hmmm...didn't know DataAdapter was a type. Thanks.

Regards

"Armin Zingler" <az.nospam@freenet.de> wrote in message
news:uY894l9rIHA.3632@TK2MSFTNGP04.phx.gbl...
> "John" <info@nospam.infovis.co.uk> schrieb
>> 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



Re: Passing various class types as parameters by John

John
Tue May 06 20:04:43 CDT 2008

Dim x as DataAdapter
x = MyTableDataAdapter

dose not work as MyTableDataAdapter can not be converted to DataAdapter

"Armin Zingler" <az.nospam@freenet.de> wrote in message
news:uY894l9rIHA.3632@TK2MSFTNGP04.phx.gbl...
> "John" <info@nospam.infovis.co.uk> schrieb
>> 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



Re: Passing various class types as parameters by Armin

Armin
Tue May 06 20:34:49 CDT 2008

"John" <info@nospam.infovis.co.uk> schrieb
> 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