473,511 Members | 15,818 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Structure Assignment

Hello:

Is there a way to assign a structure from the result of <structure>.ToString
in one statement?

For instance, if such function existed, it might look like this:

Me.Size = OurFunction(Me.Size.Tostring)
thanks,

Vadim

Nov 20 '05 #1
3 1030
* "Vadim Rapp" <vr@myrealbox.nospam.com> scripsit:
Is there a way to assign a structure from the result of
<structure>.ToString in one statement?
For instance, if such function existed, it might look like this:

Me.Size = OurFunction(Me.Size.Tostring)


There is no general way to do that. You can look if the type has a
'Parse' method and then use this method to construct an object of the
type from the data contained in the string.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2
Vadim,
Have you tried:

Public Function OurFunction(ByVal s As String) As Size
' magic to convert s to a Size.
End Function

Note: I would normally create "OurFunction" as a Shared function called
Parse:

Public Structure MyStruct

Private ReadOnly m_value As Integer

Public Sub New(ByVal value As Integer)
m_value = value
End Sub

Public Overrides Function ToString() As String
Return m_value.ToString()
End Function

Public Shared Function Parse(ByVal s As String) As MyStruct
Return New MyStruct(Integer.Parse(s))
End Function

End Structure

Note: I would consider using String.Split to parse the input string to the
Parse function.

Hope this helps
Jay

"Vadim Rapp" <vr@myrealbox.nospam.com> wrote in message
news:eK**************@TK2MSFTNGP11.phx.gbl...
Hello:

Is there a way to assign a structure from the result of <structure>.ToString in one statement?

For instance, if such function existed, it might look like this:

Me.Size = OurFunction(Me.Size.Tostring)
thanks,

Vadim

Nov 20 '05 #3
Vadim,
I should add that normally you do not need to convert structures to strings
to assign them to structure variables, you can simply assign one structure
to another

Dim frm1 As Form
Dim frm2 As Form
frm1.Size = frm2.Size

Hope this helps
Jay

"Vadim Rapp" <vr@myrealbox.nospam.com> wrote in message
news:eK**************@TK2MSFTNGP11.phx.gbl...
Hello:

Is there a way to assign a structure from the result of <structure>.ToString in one statement?

For instance, if such function existed, it might look like this:

Me.Size = OurFunction(Me.Size.Tostring)
thanks,

Vadim

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1591
by: D Witherspoon | last post by:
I have a Structure I have created and am using it as a Public Property of a class. Here is the property. ------------------------------------------------------ Dim _MyID As SInteger Public...
4
2484
by: steflhermitte | last post by:
Dear cpp-ians, I am working with a structure struct segment { .... vector <meta_segment>::iterator it_Z; .... };
4
4676
by: Trying_Harder | last post by:
Consider the following declaration, #include <stdio.h> #include <stdlib.h> typedef struct foo { char name; int age; }Foo;
7
2694
by: Brian K. Michalk | last post by:
I know I can assign default values to a structure during initialization, but I have a routine that accumulates a lot of floats into an array, and then I would like to assign them to a (reference to...
6
7806
by: Pushkar Pradhan | last post by:
I have a struct like this: struct point { int x; int y; }; Then I need to assign a certain point "=" another pt. eg. struct point p1, pArr;
15
38062
by: Sourcerer | last post by:
Hi all. Can I do this to duplicate the contents of struct a in struct b struct myStruct a, b, *aptr, *bptr; aptr = a; bptr = b; Do something to initialize contents of structure a...
2
8243
by: Suzie | last post by:
I'm a newbie with Vb.NET so please excuse me if this is a stupid quetion. I have declared a structure: Structure ClientRecord Public Client_ID As Integer Public Client_Initials As String...
8
3434
by: SP | last post by:
The following code crashes after I add the two nested FOR loops at the end, I am starting to learn about pointers and would like to understand what I'm doing wrong. I think the problem is the way...
6
1614
by: krishna | last post by:
Hi , When i read linux tcp/ip stack codes i come cross lot of structure assignment like this. I guess '=' is the assignment operator and is there any particular reason for using ':' as the...
2
13001
by: subramanian100in | last post by:
Suppose I need to assign one structure to another. Should each member of the structure be assigned individually or can memcpy be used ? Since the compiler can add padding bytes, which approach...
0
7252
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7153
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
7432
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...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1583
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.