E
Eric A. Johnson
I'm trying to figure out if there is any way to create a Property for a
private array member. I have tried it like this:
' Property for the length of a side
Public Property SideLength(ByVal sideNumber As Integer) As Integer
Get
Return mSideLength(sideNumber)
End Get
Set(ByVal sideNum As Integer, ByVal Value As Integer)
mSideLength(sideNum) = Value
End Set
End Property
....and the declaration is like so:
' Array containing the length of each side
Private mSideLength As Integer()
' ...miscellaneous code...
mSideLength = New Integer(mSides - 1) _
{side1, side2, side3}
.... where msides is equal to the number of sides for the shape (in this
case, 3, as it is a triangle). The errors I am getting in declaring the
property are as follows:
C:\Documents and Settings\Eric\Desktop\Eric\School\Advanced VB
2\Shapes\ShapeLibrary\Triangle.vb(82): 'Set' method cannot have more than
one parameter.
C:\Documents and Settings\Eric\Desktop\Eric\School\Advanced VB
2\Shapes\ShapeLibrary\Triangle.vb(83): Name 'Value' is not declared.
I can tell you why I want to use this as a property, if you want, but
mainly, I want to know how (and if!) it is possible to Get/Set an array
member as a property. How would I code it? The book I have doesn't tell me
if it is or isn't possible.
-- Eric
private array member. I have tried it like this:
' Property for the length of a side
Public Property SideLength(ByVal sideNumber As Integer) As Integer
Get
Return mSideLength(sideNumber)
End Get
Set(ByVal sideNum As Integer, ByVal Value As Integer)
mSideLength(sideNum) = Value
End Set
End Property
....and the declaration is like so:
' Array containing the length of each side
Private mSideLength As Integer()
' ...miscellaneous code...
mSideLength = New Integer(mSides - 1) _
{side1, side2, side3}
.... where msides is equal to the number of sides for the shape (in this
case, 3, as it is a triangle). The errors I am getting in declaring the
property are as follows:
C:\Documents and Settings\Eric\Desktop\Eric\School\Advanced VB
2\Shapes\ShapeLibrary\Triangle.vb(82): 'Set' method cannot have more than
one parameter.
C:\Documents and Settings\Eric\Desktop\Eric\School\Advanced VB
2\Shapes\ShapeLibrary\Triangle.vb(83): Name 'Value' is not declared.
I can tell you why I want to use this as a property, if you want, but
mainly, I want to know how (and if!) it is possible to Get/Set an array
member as a property. How would I code it? The book I have doesn't tell me
if it is or isn't possible.
-- Eric