472,354 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,354 software developers and data experts.

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 2876
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Robert Oschler | last post by:
Has anybody seen a Python module that will take an XML document (not a colossal one), and convert it to a Python nested class object? I'm basically looking for something that would allow me to...
4
by: Thomas Paul Diffenbach | last post by:
Can anyone point me to an open source library of /statically allocated/ data structures? I'm writing some code that would benefit from trees, preferably self balancing, but on an embedded system...
2
by: Mike Jeffers | last post by:
Hi everyone, I need to convert data from a structure into hexadecimal ascii format. The structure is like this: struct ROOM_DATA { short room_number; short floor_number; long total_area;
11
by: theshowmecanuck | last post by:
As a matter of academic interest only, is there a way to programmatically list the 'c' data types? I am not looking for detail, just if it is possible, and what function could be used to...
3
by: Kiran B. | last post by:
Hi, I am new to .net. I have two Data Structure Type ... Sturcture A and Structure B. Structure A Public Fname as String Public LastName as String Public City as String Public Zip as String...
3
by: bolly | last post by:
Hi, I've been putting Python data into a sqlite3 database as tuples but when I retrieve them they come back as unicode data e.g 'u(1,2,3,4)'.How can I change it back to a tuple so I can use it as...
30
by: Charles Law | last post by:
Here's one that should probably have the sub-heading "I'm sure I asked this once before, but ...". Two users are both looking at the same data, from a database. One user changes the data and...
10
by: Frank Rizzo | last post by:
Given the inneficiencies of ArrayList and Hashtable on 64-bit systems, I am converting them to List<and Dictionary<respectively. It's a pretty massive system, so there are a lot of casts. For...
10
by: John Brown | last post by:
Hi there, Does anyone know how to go about reading/writing a type to a file in a language (culture) independent way. For instance, let's say you're dealing with the native "System.Drawing.Size"...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made but the http to https rule only works for...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.