TypeOF

  • Thread starter Thread starter Jim Heavey
  • Start date Start date
J

Jim Heavey

I want to know if the type of data of one object is the same type as another
object.
The "TypeOf" function let's me find out it the object is integer or string
or.... but it does not seem to allow me to compare the types of 2 object to
see if the are of the same type.

How do I do this?

dim item1 as string = "Fred"
dim Item2 as Integer = 37
values(0) = item1
values(1) = item2

if typeof row.Item(0) is typeof values(1)
 
Try this:

If TypeOf row.Item(0) Is GetType(values(1)) Then
...
End If

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit
 
Hello,

Jim Heavey said:
I want to know if the type of data of one object is the same
type as another object.

The same type or assignable?
The "TypeOf" function let's me find out it the object is integer
or string or.... but it does not seem to allow me to compare the
types of 2 object to see if the are of the same type.

How do I do this?

dim item1 as string = "Fred"
dim Item2 as Integer = 37
values(0) = item1
values(1) = item2

if typeof row.Item(0) is typeof values(1)

You need something like this:

\\\

' Same type.
If b.GetType() Is c.GetType() Then
...
End If

' Assignable.
If b.GetType().IsAssignableFrom(c.GetType()) Then
...
End If
///

HTH,
Herfried K. Wagner
 
Ok.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit
 
I was minding my own business when Herfried K. Wagner [MVP] blurted out:
Hello,



Doesn't work.

Regards,
Herfried K. Wagner

Real helpful post there. Kinda like a lot of your posts.
 
You certainly are not a troll, if they are mean again, I'll get
System.Reflection onto them.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Maybe it's a game called 'Punish the User'"
 
Herfried K. Wagner [MVP] was minding his own business when -=Chris=-
blurted out:

|| Real helpful post there. Kinda like a lot of your posts.


Dear Chris,

Herfried spends plenty of time here helping people. Like the rest of us.
Sometimes he's completely serious, sometime less so, sometimes off topic.
Sometimes he has time to do a full answer, sometimes he does not. Sometimes he
gets it right, sometimes he gets it less right. Occasionally he's wrong. Like
the rest of us.

You are not counted in "the rest of us". I have never seen any help given
with the tag -=Chris=-.

|| Kinda like a lot of your posts.

So where are your replies guiding the questioner in the right direction?
Where's your contribution?

|| Real helpful post there.

Herfried was giving information - that the code didn't work for him.. It
was terse, but it was also valid.

Your post, on the other hand, is just a plain old moaning criticism. It
contains no information of value whatsoever.

Feel free to have your opinions. Feel free to post them here to us. Feel
free to be jumped on.

Yours, pugilistically,
Fergus

Corny line:
-=Chris=- did miss, when he tried to diss. Dismiss -=Chris=-.
 
Hi Tom,

This is a System.ArgumentNullException.

We may have to get tougher and call in System.Diagnostics and/or
System.Security.

Regards,
Fergus

ps:
Cor were you referring to -=Chris=- as the Troll?
 
Back
Top