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

Accessing Structure Members

P: n/a
I am having a problem accessing the members in a structure via an interface
and Class.

***Development Code***
Structure Person
Public Name as String
End Structure

Interface IData
Public Property Employee As Person
End Interface

Public Class MyObject
Implements IData
End Class
**************

***Client Code***
Sub Main
Dim m as New MyObject
m.Employee.Name = "John"
End
**************

The problem is with the m.Employee.Name = "John" line. The IDE tells me
that since it is non-shared, I can't assign a value to it.

Is this not the right way to use structures?

Thanks
Aug 3 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hello John,

It would be correct except you didnt really implement the interface. You
told the object you were going to implement it.. but you didnt.

Public Class MyObject ' Why the hell do people insist on using that My*
crap???
Implements IData

Private oEmployee As Person = New Person

Public Property Employee As Person Implements IData.Employee
Get
Return oEmployee
End Get
Set (byval tValue as Person)
oEmployee = tValue
End Set
End Property

End Class
I dont know how you got the code to compile without implementing the property.

-Boo

I am having a problem accessing the members in a structure via an
interface and Class.

***Development Code***
Structure Person
Public Name as String
End Structure
Interface IData
Public Property Employee As Person
End Interface
Public Class MyObject
Implements IData
End Class
**************

***Client Code***
Sub Main
Dim m as New MyObject
m.Employee.Name = "John"
End
**************

The problem is with the m.Employee.Name = "John" line. The IDE tells
me that since it is non-shared, I can't assign a value to it.

Is this not the right way to use structures?

Thanks

Aug 4 '06 #2

P: n/a
Hi Boo-

Thank you for your reply. I tried to keep my original post short and to the
point so I didn't include all the code in my post. Specifically, the
interface was implemented, I just didn't show it. Here is the actual code:
(apologies in advance for the My* crap :-) )

****Development Code****
Public Structure sPerson
Public FirstName As String
Public LastName As String
Public FullName As String
Public Phone As String
End Structure

Public Interface IReportData
Property Requestor() As sPerson
Property Engineer() As sPerson
End Interface

Public Class ExcelRequestForm
Implements IReportData

Private mEngineer As sPerson = New sPerson
Private mRequestor As sPerson = New sPerson

Public Property Engineer() As SPerson Implements
IReportData.Engineer
Get
Return mEngineer
End Get
Set(ByVal Value As SPerson)
mEngineer = Value
End Set
End Property

Public Property Requestor() As SPerson Implements
IReportData.Requestor
Get
Return mRequestor
End Get
Set(ByVal Value As SPerson)
mRequestor = Value
End Set
End Property

End Class
*******************

***Client Code***
Sub Main
Dim myTest As New ExcelRequestForm
myTest.Engineer.FirstName = "John" '<---THIS LINE DOESN'T COMPILE
End Sub
**************

The IDE tells me that the "myTest.Engineer.Firstname" is an expression that
is a value and cannot be the target of an assignment... or some nonsense like
that.

Thanks again for your time-

John
"GhostInAK" wrote:
Hello John,

It would be correct except you didnt really implement the interface. You
told the object you were going to implement it.. but you didnt.

Public Class MyObject ' Why the hell do people insist on using that My*
crap???
Implements IData

Private oEmployee As Person = New Person

Public Property Employee As Person Implements IData.Employee
Get
Return oEmployee
End Get
Set (byval tValue as Person)
oEmployee = tValue
End Set
End Property

End Class
I dont know how you got the code to compile without implementing the property.

-Boo

I am having a problem accessing the members in a structure via an
interface and Class.

***Development Code***
Structure Person
Public Name as String
End Structure
Interface IData
Public Property Employee As Person
End Interface
Public Class MyObject
Implements IData
End Class
**************

***Client Code***
Sub Main
Dim m as New MyObject
m.Employee.Name = "John"
End
**************

The problem is with the m.Employee.Name = "John" line. The IDE tells
me that since it is non-shared, I can't assign a value to it.

Is this not the right way to use structures?

Thanks


Aug 7 '06 #3

P: n/a
Hello John,

Heh. That's a fun one. I can't give you the detailed technical description
of exactly whats going on.. but here's a quick glossover..
Structures are value types. Just like an Int16 or a Boolean. So, just like
an Int16, you wouldnt assign a value to a portion of the variable. Like..
you wouldn't assign byte 2 of an Int16 directly (yeah, you could construct
an Int16 from an array of bytes using the BitConverter.. that's not the point).
Point is, you have to assign ExcelRequestForm.Engineer. Not a portion of
..Engineer.

Dim tForm as ExcelRequestForm = New ExcelRequestForm
Dim tEngineer as sPerson = new sPreson

tEngineer.FirstName = "John"
tForm.Engineer = tEngineer
(You may want to add a ctor or two to the struct.)

-Boo
Hi Boo-

Thank you for your reply. I tried to keep my original post short and
to the point so I didn't include all the code in my post.
Specifically, the interface was implemented, I just didn't show it.
Here is the actual code: (apologies in advance for the My* crap :-) )

****Development Code****
Public Structure sPerson
Public FirstName As String
Public LastName As String
Public FullName As String
Public Phone As String
End Structure
Public Interface IReportData
Property Requestor() As sPerson
Property Engineer() As sPerson
End Interface
Public Class ExcelRequestForm
Implements IReportData
Private mEngineer As sPerson = New sPerson
Private mRequestor As sPerson = New sPerson
Public Property Engineer() As SPerson Implements
IReportData.Engineer
Get
Return mEngineer
End Get
Set(ByVal Value As SPerson)
mEngineer = Value
End Set
End Property
Public Property Requestor() As SPerson Implements
IReportData.Requestor
Get
Return mRequestor
End Get
Set(ByVal Value As SPerson)
mRequestor = Value
End Set
End Property
End Class
*******************
***Client Code***
Sub Main
Dim myTest As New ExcelRequestForm
myTest.Engineer.FirstName = "John" '<---THIS LINE DOESN'T
COMPILE
End Sub
**************

The IDE tells me that the "myTest.Engineer.Firstname" is an expression
that is a value and cannot be the target of an assignment... or some
nonsense like that.

Thanks again for your time-

John

"GhostInAK" wrote:
>Hello John,

It would be correct except you didnt really implement the interface.
You told the object you were going to implement it.. but you didnt.

Public Class MyObject ' Why the hell do people insist on using
that My*
crap???
Implements IData
Private oEmployee As Person = New Person

Public Property Employee As Person Implements IData.Employee
Get
Return oEmployee
End Get
Set (byval tValue as Person)
oEmployee = tValue
End Set
End Property
End Class

I dont know how you got the code to compile without implementing the
property.

-Boo
>>I am having a problem accessing the members in a structure via an
interface and Class.

***Development Code***
Structure Person
Public Name as String
End Structure
Interface IData
Public Property Employee As Person
End Interface
Public Class MyObject
Implements IData
End Class
**************
***Client Code***
Sub Main
Dim m as New MyObject
m.Employee.Name = "John"
End
**************
The problem is with the m.Employee.Name = "John" line. The IDE
tells me that since it is non-shared, I can't assign a value to it.

Is this not the right way to use structures?

Thanks


Aug 7 '06 #4

P: n/a
Ahhh... okay. That works now. I didn't know you could add constructors to
Structures (i.e. I didn't think they could contain any working code).

Thanks for your help Boo!

John

"GhostInAK" wrote:
Hello John,

Heh. That's a fun one. I can't give you the detailed technical description
of exactly whats going on.. but here's a quick glossover..
Structures are value types. Just like an Int16 or a Boolean. So, just like
an Int16, you wouldnt assign a value to a portion of the variable. Like..
you wouldn't assign byte 2 of an Int16 directly (yeah, you could construct
an Int16 from an array of bytes using the BitConverter.. that's not the point).
Point is, you have to assign ExcelRequestForm.Engineer. Not a portion of
..Engineer.

Dim tForm as ExcelRequestForm = New ExcelRequestForm
Dim tEngineer as sPerson = new sPreson

tEngineer.FirstName = "John"
tForm.Engineer = tEngineer
(You may want to add a ctor or two to the struct.)

-Boo
Hi Boo-

Thank you for your reply. I tried to keep my original post short and
to the point so I didn't include all the code in my post.
Specifically, the interface was implemented, I just didn't show it.
Here is the actual code: (apologies in advance for the My* crap :-) )

****Development Code****
Public Structure sPerson
Public FirstName As String
Public LastName As String
Public FullName As String
Public Phone As String
End Structure
Public Interface IReportData
Property Requestor() As sPerson
Property Engineer() As sPerson
End Interface
Public Class ExcelRequestForm
Implements IReportData
Private mEngineer As sPerson = New sPerson
Private mRequestor As sPerson = New sPerson
Public Property Engineer() As SPerson Implements
IReportData.Engineer
Get
Return mEngineer
End Get
Set(ByVal Value As SPerson)
mEngineer = Value
End Set
End Property
Public Property Requestor() As SPerson Implements
IReportData.Requestor
Get
Return mRequestor
End Get
Set(ByVal Value As SPerson)
mRequestor = Value
End Set
End Property
End Class
*******************
***Client Code***
Sub Main
Dim myTest As New ExcelRequestForm
myTest.Engineer.FirstName = "John" '<---THIS LINE DOESN'T
COMPILE
End Sub
**************

The IDE tells me that the "myTest.Engineer.Firstname" is an expression
that is a value and cannot be the target of an assignment... or some
nonsense like that.

Thanks again for your time-

John

"GhostInAK" wrote:
Hello John,

It would be correct except you didnt really implement the interface.
You told the object you were going to implement it.. but you didnt.

Public Class MyObject ' Why the hell do people insist on using
that My*
crap???
Implements IData
Private oEmployee As Person = New Person

Public Property Employee As Person Implements IData.Employee
Get
Return oEmployee
End Get
Set (byval tValue as Person)
oEmployee = tValue
End Set
End Property
End Class

I dont know how you got the code to compile without implementing the
property.

-Boo

I am having a problem accessing the members in a structure via an
interface and Class.

***Development Code***
Structure Person
Public Name as String
End Structure
Interface IData
Public Property Employee As Person
End Interface
Public Class MyObject
Implements IData
End Class
**************
***Client Code***
Sub Main
Dim m as New MyObject
m.Employee.Name = "John"
End
**************
The problem is with the m.Employee.Name = "John" line. The IDE
tells me that since it is non-shared, I can't assign a value to it.

Is this not the right way to use structures?

Thanks

Aug 7 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.