Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 1st, 2005, 01:33 PM
Authorized User
 
Join Date: Jun 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default ERROR: "property access must assign to the proper"

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("Attempting to start MyCar with AlexKey: ")
      MyCar.Ignition(AlexKey) 'MyCar.Ignition(AlexKey)
      'Response.Write(MyCar.IsRunning)

      'Response.Write("attemtping to start MyCar with RobKey: ")
      'MyCar.Ignition(RobKey)
      'Response.Write(MyCar.IsRunning)

      'Response.Write("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

 
Old July 1st, 2005, 01:47 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

You are accessing a GET property you have to assign the return value to a variable.

 
Old July 1st, 2005, 02:25 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You are trying to call a property as a method. You have to set properties like with assignments like this:

MyCar.Ignition = AlexKey

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable so assign value to .Lookin Property Colster Excel VBA 1 August 24th, 2007 03:16 PM
Convert text from excel to proper date in access bprodman Access VBA 1 June 18th, 2007 03:48 PM
Can you Assign a Collection to a Property? MandMD2 Beginning VB 6 2 May 3rd, 2007 05:24 PM
Re-assign the Control ID after Postback / Error AbrarNazeer ASP.NET 2.0 Professional 6 July 22nd, 2006 11:34 PM
Access to a property in the class. AyatKh ASP.NET 1.0 and 1.1 Basics 2 December 18th, 2003 11:25 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.