converting data types (object back to structure type)

B

Brian Henry

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
 
B

Brian Henry

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?
 
B

Brian Henry

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top