Odd Error, Structure, Property Assignment...

JaedenRuiner

Well-known member
Joined
Aug 13, 2007
Messages
340
Programming Experience
10+
Okay, this is all code, so i'll just give it flat out:

VB.NET:
Public Structure Coordinates
  Private f_Row As Integer
  Private f_Col As Integer

  Shared Operator <>(ByVal C As Coordinates, ByVal value As Integer) As Boolean
    Return CBool((C.f_Col * C.f_Row) <> value)
  End Operator

  Shared Operator =(ByVal C As Coordinates, ByVal value As Integer) As Boolean
    Return CBool((C.f_Col * C.f_Row) = value)
  End Operator

  Shared Operator <>(ByVal C1 As Coordinates, ByVal C2 As Coordinates) As Boolean
    Return CBool((C1.f_Col <> C2.f_Col) OrElse (C1.f_Row <> C2.f_Row))
  End Operator

  Shared Operator =(ByVal C1 As Coordinates, ByVal C2 As Coordinates) As Boolean
    Return CBool((C1.f_Col = C2.f_Col) AndAlso (C1.f_Row = C2.f_Row))
  End Operator

  Public Property Row() As Integer
    Get
      Return f_Row
    End Get
    Set(ByVal value As Integer)
      f_Row = value
    End Set
  End Property

  Public Property Column() As Integer
    Get
      Return f_Col
    End Get
    Set(ByVal value As Integer)
      f_Col = value
    End Set
  End Property

  Public Sub New(ByVal iRow As Integer, ByVal iCol As Integer)
    f_Row = iRow
    f_Col = iCol
  End Sub
End Structure
The Ancestor Class:
VB.NET:
public mustinherit class MyClass1
  Protected MustOverride Sub SetDimensions(ByVal Size As Coordinates)

  Private f_Extents As Coordinates = New Coordinates(0, 0)

  Protected Property Size() As Coordinates
    Get
      Return f_Extents
    End Get
    Set(ByVal value As Coordinates)
      f_Extents = value
    End Set
  End Property

end class
The Descendant Class:
VB.NET:
Public Class MyClass2
  Inherits MyClass1

  Protected Overrides Sub SetDimensions(ByVal rSize As Coordinates)
    If rSize = 0 Then
      If rSize.Row = 0 Then rSize.Row += 1
      If rSize.Column = 0 Then rSize.Column += 1
    End If
    If Compare(rSize, Me.Size) = 0 Then Exit Sub
    If Compare(rSize, Me.Size) > 0 Then
      While Me.Size.Column < rSize.Column
        AddColumn()
>>>        Me.Size.Column += 1  <<<<<
      End While
    Else

    End If
    Me.Size = Size
  End Sub
On the Marked Line I get this error from the compilter (VS.NET 2005)
Error 9 Expression is a value and therefore cannot be the target of an assignment.

Why is the parameter on the stack able to perform the assignment operation while the Class Property cannot?

Thanks
Jaeden "Sifo Dyas" al'Raec Ruiner
 
Me.Size returns a value (structure instance), not a reference. You can get the Size, operate it, then reassign a new Size. You can also expose the Column as a property of its own. jmcilhinney had an extended explanation about this recently: http://www.vbdotnetforums.com/showthread.php?t=24796
 
Back
Top