|
Subject:
|
ERROR: "property access must assign to the proper"
|
|
Posted By:
|
anpham
|
Post Date:
|
7/1/2005 1:33:41 PM
|
below is the code i wrote, you'll find where the error is at below "bold & red" the error states... "property access must assign to the property or use its value."
what does that mean????
Public Class WebForm1 Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
'NOTE: The following placeholder declaration is required by the Web Form Designer. 'Do not delete or move it. Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub
#End Region
Public Class Car Private _Color As String = "no color yet" Private _Gear As Integer Private _Ignition As Integer Private _EngineRunning As Boolean Private Shared _Count As Integer = 0
Public Sub New(ByVal IgnitionShape As Integer) _Color = "cold grey steel" _Ignition = IgnitionShape _Count += 1 End Sub
Public Sub EngineOFF() _EngineRunning = False End Sub
Public ReadOnly Property IsRunning() As String Get If _EngineRunning Then Return "The engine is running." Else Return "The engine is not running." End If End Get End Property
Public ReadOnly Property Ignition(ByVal IgnitionKey As Key) As Integer Get If IgnitionKey.Shape = _Ignition Then _EngineRunning = True End Get End Property
Public Overloads Sub ChangeGear(ByVal direction As Integer) If direction < 0 Then _Gear -= 1 If direction > 0 Then _Gear += 1 If _Gear > 5 Then _Gear = 5 If _Gear < -1 Then _Gear = -1 End Sub
Public Overloads Sub ChangeGear(ByVal direction As String) If direction = "up" Then ChangeGear(1) If direction = "down" Then ChangeGear(-1) End Sub
Public Property Color() As String Get Return _Color End Get Set(ByVal Value As String) _Color = Value End Set End Property
Public Shared ReadOnly Property Count() As Integer Get Return _Count End Get End Property
Public ReadOnly Property Gear() As Integer Get Return _Gear End Get End Property
End Class
Public Class Key Private _Shape As Integer
Public Sub New(ByVal NewShape As Integer) _Shape = NewShape End Sub
Public ReadOnly Property Shape() As Integer Get Return _Shape End Get End Property End Class
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim AlexKey As New Key(987654321) Dim RobKey As New Key(1861005040) Dim AnKey As New Key(1234567890)
Dim MyCar As New Car(1234567890) Response.Write("<b>New object 'MyCar' created.</b>") Response.Write("<br>Color: " & MyCar.Color) Response.Write("<br>Gear: " & MyCar.Gear)
MyCar.Color = "Black" MyCar.ChangeGear(+1) Response.Write("<br><b>Properties updated.</b><br>") Response.Write("New color: " & MyCar.Color & "<br>" & "New Gear: " & MyCar.Gear & "<br>")
MyCar.ChangeGear("up") Response.Write("<b>Shifted 'up' one gear.</b><br>" & "New gear: " & MyCar.Gear)
Response.Write("<hr>Attempting to start MyCar with AlexKey: ") MyCar.Ignition(AlexKey) 'MyCar.Ignition(AlexKey) 'Response.Write(MyCar.IsRunning)
'Response.Write("<hr>attemtping to start MyCar with RobKey: ") 'MyCar.Ignition(RobKey) 'Response.Write(MyCar.IsRunning)
'Response.Write("<hr>attempting to start MyCar with AnKey: ") 'MyCar.Ignition(AnKey) 'Response.Write(MyCar.IsRunning)
'Response.Write("attempting to stop MyCar: ") 'MyCar.EngineOFF() 'Response.Write(MyCar.IsRunning)
End Sub
End Class
|
|
Reply By:
|
jbenson001
|
Reply Date:
|
7/1/2005 1:47:44 PM
|
You are accessing a GET property you have to assign the return value to a variable.
|
|
Reply By:
|
planoie
|
Reply Date:
|
7/1/2005 2:25:17 PM
|
You are trying to call a property as a method. You have to set properties like with assignments like this:
MyCar.Ignition = AlexKey
-Peter
|