PC Review


Reply
Thread Tools Rate Thread

Typecasting without knowing the cast

 
 
John
Guest
Posts: n/a
 
      28th Apr 2008
Hi

I have a data row variable which could be for any of a number of tables in
my apps. How can I type cast the variable to correct type at runtime? I know
I can get the type description using MyRow.ToString but don't know how to
use this to typecast MyRow variable. I need this to write a generic SUB that
can deal with rows of any table type.

Thanks

Regards


 
Reply With Quote
 
 
 
 
Armin Zingler
Guest
Posts: n/a
 
      28th Apr 2008
"John" <(E-Mail Removed)> schrieb
> Hi
>
> I have a data row variable which could be for any of a number of
> tables in my apps. How can I type cast the variable to correct type
> at runtime? I know I can get the type description using
> MyRow.ToString but don't know how to use this to typecast MyRow
> variable. I need this to write a generic SUB that can deal with rows
> of any table type.


Maybe you are looking for this:

if typeof row is CustomerRow then
directcast(row, CustomerRow).Member 'any type specific member
elseif typeof row is contractRow then

'...

end if

Type casting without knowing the destination type at design time does
not make sense. Casting is there to be able to write code that is
specific to a certain type. If you don't know the destination type, you
can not write type specific code.


Armin

 
Reply With Quote
 
kimiraikkonen
Guest
Posts: n/a
 
      28th Apr 2008
On Apr 28, 10:31 pm, "John" <i...@nospam.infovis.co.uk> wrote:
> Hi
>
> I have a data row variable which could be for any of a number of tables in
> my apps. How can I type cast the variable to correct type at runtime? I know
> I can get the type description using MyRow.ToString but don't know how to
> use this to typecast MyRow variable. I need this to write a generic SUB that
> can deal with rows of any table type.
>
> Thanks
>
> Regards


John,
To know the type of object, use GetType function to determine. Then
maybe you'll have a change for type casting.

Hope this helps,

Onur
 
Reply With Quote
 
Tom Shelton
Guest
Posts: n/a
 
      29th Apr 2008
On 2008-04-28, John <(E-Mail Removed)> wrote:
> Hi
>
> I have a data row variable which could be for any of a number of tables in
> my apps. How can I type cast the variable to correct type at runtime? I know
> I can get the type description using MyRow.ToString but don't know how to
> use this to typecast MyRow variable. I need this to write a generic SUB that
> can deal with rows of any table type.
>
> Thanks
>
> Regards
>
>


Assuming that Row inherits from DataRow, then that is the type you would
be working with.

--
Tom Shelton
 
Reply With Quote
 
John
Guest
Posts: n/a
 
      29th Apr 2008
I am trying

CType(MyRow, GetType(MyRow))

but it says 'Error 1 Keyword does not name a type' on GetType.

Thanks

Regards


"kimiraikkonen" <(E-Mail Removed)> wrote in message
news:0be0e139-0b2a-4e4b-bf00-(E-Mail Removed)...
> On Apr 28, 10:31 pm, "John" <i...@nospam.infovis.co.uk> wrote:
>> Hi
>>
>> I have a data row variable which could be for any of a number of tables
>> in
>> my apps. How can I type cast the variable to correct type at runtime? I
>> know
>> I can get the type description using MyRow.ToString but don't know how to
>> use this to typecast MyRow variable. I need this to write a generic SUB
>> that
>> can deal with rows of any table type.
>>
>> Thanks
>>
>> Regards

>
> John,
> To know the type of object, use GetType function to determine. Then
> maybe you'll have a change for type casting.
>
> Hope this helps,
>
> Onur



 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      29th Apr 2008
"John" <(E-Mail Removed)> schrieb
> I am trying
>
> CType(MyRow, GetType(MyRow))
>
> but it says 'Error 1 Keyword does not name a type' on GetType.


Have you read my message? Why do you want to cast at all?


Armin
 
Reply With Quote
 
John
Guest
Posts: n/a
 
      29th Apr 2008
I am writing a library of generalised SUB to handle any table's row that the
user using the library may need to pass to library. I do not know the actual
type of the data row that user will be passing therefore I need to figure it
at runtime.

Thanks

Regards

"Armin Zingler" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "John" <(E-Mail Removed)> schrieb
>> I am trying
>>
>> CType(MyRow, GetType(MyRow))
>>
>> but it says 'Error 1 Keyword does not name a type' on GetType.

>
> Have you read my message? Why do you want to cast at all?
>
>
> Armin



 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      29th Apr 2008
"John" <(E-Mail Removed)> schrieb
> I am writing a library of generalised SUB to handle any table's row
> that the user using the library may need to pass to library. I do
> not know the actual type of the data row that user will be passing
> therefore I need to figure it at runtime.


Sry, I don't get it. If you don't know the actual type, how do you want
to handle different types differently? That's a contradiction.

If you determine the type at _runtime_, how do you want to take the type
into account at _design time_? Design time is before runtime.


Armin

 
Reply With Quote
 
Tom Shelton
Guest
Posts: n/a
 
      29th Apr 2008
On 2008-04-28, John <(E-Mail Removed)> wrote:
> I am writing a library of generalised SUB to handle any table's row that the
> user using the library may need to pass to library. I do not know the actual
> type of the data row that user will be passing therefore I need to figure it
> at runtime.
>
> Thanks


John,

What kind of actions are you trying to take on these rows? Basically,
what I'm saying, is unless you know the type or the types that can be
passed, then you can't get there from here....

Like I said, you can handle all the Rows as DataRow, and that is about
as close as your going to get.

--
Tom Shelton
 
Reply With Quote
 
John
Guest
Posts: n/a
 
      29th Apr 2008
Thanks. I know what you mean.

Regards

"Armin Zingler" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "John" <(E-Mail Removed)> schrieb
>> I am writing a library of generalised SUB to handle any table's row
>> that the user using the library may need to pass to library. I do
>> not know the actual type of the data row that user will be passing
>> therefore I need to figure it at runtime.

>
> Sry, I don't get it. If you don't know the actual type, how do you want
> to handle different types differently? That's a contradiction.
>
> If you determine the type at _runtime_, how do you want to take the type
> into account at _design time_? Design time is before runtime.
>
>
> Armin
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Typecasting without knowing the cast John Microsoft VB .NET 11 29th Apr 2008 07:29 AM
Dynamic Typecasting =?Utf-8?B?aG9udXM=?= Microsoft VB .NET 8 21st Aug 2007 03:09 PM
typecasting ??? cmrchs@yahoo.com Microsoft VC .NET 2 5th Jul 2005 07:01 PM
Typecasting Christopher Weaver Microsoft C# .NET 9 4th May 2005 08:18 AM
Typecasting problem Kelmen Wong Microsoft Dot NET Framework 1 4th May 2004 10:04 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:39 AM.