469,889 Members | 1,255 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,889 developers. It's quick & easy.

converting data types (object back to structure type)

If i have a structure type and i place the structures data into a tag
property (which is an object) it will go in obviously, but when i pull an
object back into a structrured type it will error.. how do i convert the
object back into a struct? here's an example

public structure teststruc
public name as string
public id as integer
end structure

dim a as teststruc
with a
.name = "me"
.id = 10
endwith

me.tag = a ' this part obviously works fine

' but when i do this i have a conversion error
dim b as teststruc
b = me.tag ' error here converting from object to teststruc
me.textbox1.text = b.name
how would i convert the structure back from an object? thanks
Nov 20 '05 #1
3 2707
Use CType or DirectCast

-Rob Teixeira [MVP]

"Brian Henry" <brianiup[remove-me]@adelphia.net> wrote in message
news:ee**************@TK2MSFTNGP12.phx.gbl...
If i have a structure type and i place the structures data into a tag
property (which is an object) it will go in obviously, but when i pull an
object back into a structrured type it will error.. how do i convert the
object back into a struct? here's an example

public structure teststruc
public name as string
public id as integer
end structure

dim a as teststruc
with a
.name = "me"
.id = 10
endwith

me.tag = a ' this part obviously works fine

' but when i do this i have a conversion error
dim b as teststruc
b = me.tag ' error here converting from object to teststruc
me.textbox1.text = b.name
how would i convert the structure back from an object? thanks

Nov 20 '05 #2
thanks! i knew it in my head but i just couldn't remember the names of
them... is there any real diffrence between the two?
"Rob Teixeira [MVP]" <RobTeixeira@@msn.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Use CType or DirectCast

-Rob Teixeira [MVP]

"Brian Henry" <brianiup[remove-me]@adelphia.net> wrote in message
news:ee**************@TK2MSFTNGP12.phx.gbl...
If i have a structure type and i place the structures data into a tag
property (which is an object) it will go in obviously, but when i pull an object back into a structrured type it will error.. how do i convert the
object back into a struct? here's an example

public structure teststruc
public name as string
public id as integer
end structure

dim a as teststruc
with a
.name = "me"
.id = 10
endwith

me.tag = a ' this part obviously works fine

' but when i do this i have a conversion error
dim b as teststruc
b = me.tag ' error here converting from object to teststruc
me.textbox1.text = b.name
how would i convert the structure back from an object? thanks


Nov 20 '05 #3
never mind found it

The difference between the two keywords is that CType succeeds as long as
there is a valid conversion defined between the expression and the type,
whereas DirectCast requires the run-time type of an object variable to be
the same as the specified type. If the specified type and the run-time type
of the expression are the same, however, the run-time performance of
DirectCast is better than that of CType.

"Brian Henry" <brianiup[remove-me]@adelphia.net> wrote in message
news:uE**************@TK2MSFTNGP10.phx.gbl...
thanks! i knew it in my head but i just couldn't remember the names of
them... is there any real diffrence between the two?
"Rob Teixeira [MVP]" <RobTeixeira@@msn.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Use CType or DirectCast

-Rob Teixeira [MVP]

"Brian Henry" <brianiup[remove-me]@adelphia.net> wrote in message
news:ee**************@TK2MSFTNGP12.phx.gbl...
If i have a structure type and i place the structures data into a tag
property (which is an object) it will go in obviously, but when i pull an object back into a structrured type it will error.. how do i convert the object back into a struct? here's an example

public structure teststruc
public name as string
public id as integer
end structure

dim a as teststruc
with a
.name = "me"
.id = 10
endwith

me.tag = a ' this part obviously works fine

' but when i do this i have a conversion error
dim b as teststruc
b = me.tag ' error here converting from object to teststruc
me.textbox1.text = b.name
how would i convert the structure back from an object? thanks



Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Robert Oschler | last post: by
4 posts views Thread by Thomas Paul Diffenbach | last post: by
2 posts views Thread by Mike Jeffers | last post: by
11 posts views Thread by theshowmecanuck | last post: by
3 posts views Thread by Kiran B. | last post: by
3 posts views Thread by bolly | last post: by
10 posts views Thread by Frank Rizzo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.