473,396 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 2979
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.