By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,990 Members | 2,324 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,990 IT Pros & Developers. It's quick & easy.

converting data types (object back to structure type)

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.