473,811 Members | 3,924 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using a Structure in a Class

Ren
Hi all,

I'm still rather new to .NET so I hope you'll bear with me as I try and explain
my question.

I am writing an ASP.NET application using VB.NET. I am accessing a web method
from a webservice that returns a structure. On the client side I have added the
webservice as a reference and created a class that contains the structure as a
member as well as some other variables. The structure looks something like:

Public Structure ValuationResult
Dim Reliability As Integer
Dim ShowClientID As String
Dim ShowDepartment As String
Dim ShowSource As String
Dim Valuation As ValuationStruct ure 'another structure
End Structure

And the class I'm creating looks like:

Public Class Report
Private _ID As Integer
Private _ValuationResul t As myWebservice.Va luationResult

Public Property ID as integer
Get
Return _ID
End Get
Set(ByVal Value As Integer)
_ID = Value
End Set
End Property

Public Property ValuationResult as myWebservice.Va luationResult
Get
Return _ValuationResul t
End Get
Set(ByVal Value as myWebservice.Va luationResult)
_ValuationResul t = Value
End Set
End Property

...

End Class

I am now trying to create a constructor that will allow the user to pass the
populated structure that I get back from the webservice and populate the
appropriate fields. After some trial and error I've come up with:
Public Sub New(ByVal Result As myWebservice.Va luationResult)

ValuationResult = New myWebservice.Va luationResult

Me.ValuationRes ult.Reliability = Result.Reliabil ity
Me.ValuationRes ult.ShowClientI D = Result.ShowClie ntID
Me.ValuationRes ult.ShowDepartm ent = Result.ShowDepa rtment
Me.ValuationRes ult.ShowSource = Result.ShowSour ce

ValuationResult .Valuation = New myWebservice.Va luation

Me.ValuationRes ult.Valuation.F SA = Result.Valuatio n.FSA
Me.ValuationRes ult.Valuation.P ID = Result.Valuatio n.PID

...

End Sub

Now this seems to work when I call the constructor but I am unclear exactly as
to why I need to call New for the structures and any structures contained within
the parent struct. Afterall, they are strucutures and not classes. Is it
because the struct is part of the class and no memory has yet been allocated for
it until I call New?

Also, is this the best way of doing this? Is there another more elegant way?

Thanks for your help.

Ren


Feb 15 '06 #1
3 1816
"Ren" <no****@nospam. org> schrieb
Hi all,

I'm still rather new to .NET so I hope you'll bear with me as I try
and explain my question.

I am writing an ASP.NET application using VB.NET. I am accessing a
web method from a webservice that returns a structure. On the
client side I have added the webservice as a reference and created
a class that contains the structure as a member as well as some
other variables. The structure looks something like:

Public Structure ValuationResult
Dim Reliability As Integer
Dim ShowClientID As String
Dim ShowDepartment As String
Dim ShowSource As String
Dim Valuation As ValuationStruct ure 'another structure
End Structure

And the class I'm creating looks like:

Public Class Report
Private _ID As Integer
Private _ValuationResul t As myWebservice.Va luationResult

Public Property ID as integer
Get
Return _ID
End Get
Set(ByVal Value As Integer)
_ID = Value
End Set
End Property

Public Property ValuationResult as myWebservice.Va luationResult
Get
Return _ValuationResul t
End Get
Set(ByVal Value as myWebservice.Va luationResult)
_ValuationResul t = Value
End Set
End Property

...

End Class

I am now trying to create a constructor that will allow the user to
pass the populated structure that I get back from the webservice and
populate the appropriate fields. After some trial and error I've
come up with:
Public Sub New(ByVal Result As myWebservice.Va luationResult)

ValuationResult = New myWebservice.Va luationResult

Me.ValuationRes ult.Reliability = Result.Reliabil ity
Me.ValuationRes ult.ShowClientI D = Result.ShowClie ntID
Me.ValuationRes ult.ShowDepartm ent = Result.ShowDepa rtment
Me.ValuationRes ult.ShowSource = Result.ShowSour ce

ValuationResult .Valuation = New myWebservice.Va luation

Me.ValuationRes ult.Valuation.F SA = Result.Valuatio n.FSA
Me.ValuationRes ult.Valuation.P ID = Result.Valuatio n.PID

...

End Sub

Now this seems to work when I call the constructor but I am unclear
exactly as to why I need to call New for the structures and any
structures contained within the parent struct. Afterall, they are
strucutures and not classes. Is it because the struct is part of
the class and no memory has yet been allocated for it until I call
New?

Also, is this the best way of doing this? Is there another more
elegant way?

Maybe I didn't get the point, but why don't you simply write:

Public Sub New(ByVal Result As myWebservice.Va luationResult)

_ValuationResul t = Result

End Sub

Armin
Feb 15 '06 #2
Ren
Armin,

Thanks for your reply. I realized just as I hit "send" on my post that I could
do as you suggested. What in the world was I thinking?

On Wed, 15 Feb 2006 17:17:02 +0100, "Armin Zingler" <az*******@free net.de>
wrote:
"Ren" <no****@nospam. org> schrieb
Hi all,

I'm still rather new to .NET so I hope you'll bear with me as I try
and explain my question.

I am writing an ASP.NET application using VB.NET. I am accessing a
web method from a webservice that returns a structure. On the
client side I have added the webservice as a reference and created
a class that contains the structure as a member as well as some
other variables. The structure looks something like:

<<snip>>
Also, is this the best way of doing this? Is there another more
elegant way?

Maybe I didn't get the point, but why don't you simply write:

Public Sub New(ByVal Result As myWebservice.Va luationResult)

_ValuationResul t = Result

End Sub

Armin

Feb 15 '06 #3
"Ren" <no****@nospam. org> schrieb
Armin,

Thanks for your reply. I realized just as I hit "send" on my post
that I could do as you suggested. What in the world was I
thinking?

Too many trees to see the wood. Happens. :-)

Armin
Feb 15 '06 #4

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

Similar topics

17
57403
by: gokul | last post by:
Hi, Iam a newbie to dotnet and I experience problems in using the Browser control in VB .net. Though Iam able to use it with its basic features, I need to customise it. http://www.codeproject.com/books/0764549146_8.asp The above link shows where what I want is achived in C#, but I need t oa cjhive the same in VB .net. Someone help and guidance would be much appreciated.
28
20355
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()', this.pinginterval); - but is there no way to do this without using the literal ObjectName? If I write 'this.methodName()' I get "Line 1 Char 1: Object doesn't support this property or method." in IE, and nothing happens in Firebird.
4
1605
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
11
6608
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on where the job is running, the job runs sucessfully, PDF files got generated, everything is good. If I scheduled the job to run at the time that I am not logged into the server, Access is not able to print to the printer. The error is pretty...
3
4268
by: Richard | last post by:
I have a requirement to put a GDI style circle or rectangle border around the selected row of a datagrid/ It will overlap into the row above and below the selected row. Doing this in a the OnPaint of a subclassed DataGridTextBoxColum dos not seem like a practical way to do it. I have subclassed a DataGrid and overridden the OnPaint as such:
0
3946
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen. It is almost like it is trying to implement it's own COM interfaces... below is the header, and a link to the dll+code: Zip file with header, example, and DLL:...
15
14884
by: John Alway | last post by:
Hello, I'm using a DLL I wrote in C++, and am attempting to call and use it from VB. This works fine for functions where I pass parameters by value, but I can't get pointers to work. I get the following error in the VB.net application: "An unhandled exception of Type
1
1497
by: dcs | last post by:
Hi, Can someone please help. I have a class that contains the following Structure (called MyStructure) and sub (called MainSub). And this 1st class inherits a 2nd class that contains a sub called Get_Values_From_MyStructure. My problem is in sub Get_Values_From_MyStructure. Since Get_Values_From_MyStructure is inherited by many different classes, its parameter i_obj_Structure will contain various Structure definitions. And thats a problem...
14
3290
by: Steve Teeples | last post by:
I don't understand why I cannot use a property to modify data within a struct. Can someone tell me why I get the error "Cannot modify the return value of "myData.TheData" because it is not a variable. Here is what breaks. struct Data { public Data(){} private int someData;
0
9724
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
10379
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
10394
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9201
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6882
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
5552
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...
1
4336
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
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
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.