473,387 Members | 3,821 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,387 software developers and data experts.

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 ValuationStructure 'another structure
End Structure

And the class I'm creating looks like:

Public Class Report
Private _ID As Integer
Private _ValuationResult As myWebservice.ValuationResult

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.ValuationResult
Get
Return _ValuationResult
End Get
Set(ByVal Value as myWebservice.ValuationResult)
_ValuationResult = 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.ValuationResult)

ValuationResult = New myWebservice.ValuationResult

Me.ValuationResult.Reliability = Result.Reliability
Me.ValuationResult.ShowClientID = Result.ShowClientID
Me.ValuationResult.ShowDepartment = Result.ShowDepartment
Me.ValuationResult.ShowSource = Result.ShowSource

ValuationResult.Valuation = New myWebservice.Valuation

Me.ValuationResult.Valuation.FSA = Result.Valuation.FSA
Me.ValuationResult.Valuation.PID = Result.Valuation.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 1791
"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 ValuationStructure 'another structure
End Structure

And the class I'm creating looks like:

Public Class Report
Private _ID As Integer
Private _ValuationResult As myWebservice.ValuationResult

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.ValuationResult
Get
Return _ValuationResult
End Get
Set(ByVal Value as myWebservice.ValuationResult)
_ValuationResult = 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.ValuationResult)

ValuationResult = New myWebservice.ValuationResult

Me.ValuationResult.Reliability = Result.Reliability
Me.ValuationResult.ShowClientID = Result.ShowClientID
Me.ValuationResult.ShowDepartment = Result.ShowDepartment
Me.ValuationResult.ShowSource = Result.ShowSource

ValuationResult.Valuation = New myWebservice.Valuation

Me.ValuationResult.Valuation.FSA = Result.Valuation.FSA
Me.ValuationResult.Valuation.PID = Result.Valuation.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.ValuationResult)

_ValuationResult = 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*******@freenet.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.ValuationResult)

_ValuationResult = 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
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. ...
28
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()',...
4
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...
11
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...
3
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...
0
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....
15
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...
1
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...
14
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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.