By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,881 Members | 1,148 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,881 IT Pros & Developers. It's quick & easy.

Using a Structure in a Class

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
"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

P: n/a
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

P: n/a
"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 discussion thread is closed

Replies have been disabled for this discussion.