468,532 Members | 1,716 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,532 developers. It's quick & easy.

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 945
* "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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by steflhermitte | last post: by
4 posts views Thread by Trying_Harder | last post: by
7 posts views Thread by Brian K. Michalk | last post: by
6 posts views Thread by Pushkar Pradhan | last post: by
15 posts views Thread by Sourcerer | last post: by
6 posts views Thread by krishna | last post: by
2 posts views Thread by subramanian100in | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.