473,672 Members | 2,597 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>.ToS tring
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 1038
* "Vadim Rapp" <vr@myrealbox.n ospam.com> scripsit:
Is there a way to assign a structure from the result of
<structure>.ToS tring 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(ByV al s As String) As Size
' magic to convert s to a Size.
End Function

Note: I would normally create "OurFunctio n" 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.ToStrin g()
End Function

Public Shared Function Parse(ByVal s As String) As MyStruct
Return New MyStruct(Intege r.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.n ospam.com> wrote in message
news:eK******** ******@TK2MSFTN GP11.phx.gbl...
Hello:

Is there a way to assign a structure from the result of <structure>.ToS tring 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.n ospam.com> wrote in message
news:eK******** ******@TK2MSFTN GP11.phx.gbl...
Hello:

Is there a way to assign a structure from the result of <structure>.ToS tring 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
1601
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 Property MyID() As SInteger Get
4
2500
by: steflhermitte | last post by:
Dear cpp-ians, I am working with a structure struct segment { .... vector <meta_segment>::iterator it_Z; .... };
4
4688
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
2708
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 a) structure before exiting. I would like something analogous to strcpy, but for structures. My example: in file foo.h: ----------------------------------- struct _stats { float slope;
6
7820
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
38181
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 memcpy(bptr, aptr, sizeof(myStruct));
2
8251
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 Public Client_Surname As String End Structure 'ClientRecord
8
3442
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 I access the array elements. Thanks for your help. #include <stdio.h>
6
1618
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 assignment operator.A small snippet as shown below. #include <stdio.h> int main()
2
13038
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 is always safer ?
0
8486
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8931
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8828
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6238
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5705
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4227
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4418
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2819
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 we have to send another system
2
1816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.