How do i assign values to a structure element ??

G

Guest

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

I also have declared a property which is of this type of the structure:

Public Property Client() As ClientRecord
Get
Return FClient
End Get
Set(ByVal Value As ClientRecord)
FClient = Value
End Set
End Property

Now, in another form,i wish to set the values contained in the property
Client:

frmPolicy.Client.Client_ID = CInt(lblClientID.Text)

HOWEVER - I GET THE ERROR:
'Expression is a value and therefore cannot be the target of an assignment".

HOW SHOULD I DO THE ASSIGNMENT?

Any help would be most welcome!

Thanks
Suzie
 
G

Guest

Dont worry guys - I found a better solution by declaring the ClientRecord
datatype as a class instead of a structure. Now i dont have that probelm
anymore.

While i've found a solution i still dont understand what was wrong before
with the code i had, so any comments will still be welcome ...

thanks
Suzie
 
M

Mattias Sjögren

While i've found a solution i still dont understand what was wrong before
with the code i had, so any comments will still be welcome ...

When it's a structore the property will return a copy of the FClient
value, and when you assign the Client_ID you would just end up
modifying that temporary copy.

When it's a class you get back a reference to the same object and any
changes you ake affects FClient as well.


Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top