+ Reply to Thread
Results 1 to 2 of 2

Properties in a class - can't write to them

Hybrid View

  1. #1
    Registered User
    Join Date
    02-09-2007
    Posts
    29

    Properties in a class - can't write to them

    I can’t seem to correctly use a property in a class. Here is my code:


    Public Property Get StartingLocation() As Integer
        StartingLocation = pStartingLocation
    End Property
    
    Public Property Let StartingLocation(Value As Integer)
        pStartingLocation = Value
    End Property

    Next my module:

        Dim myclass As Class1
        Set myclass = New Class1
            
        myclass.StartingLocation = 10
        MsgBox (myclass.StartingLocation)
    The messagebox displays “0”

    What the heck?
    Thanks.
    Last edited by Lazhal; 08-03-2010 at 04:41 PM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,974

    Re: Properties in a class - can't write to them

    How and where have you declared pStartingLocation? If the answer is that you haven't, then it's a local variable to each property procedure and its value does not persist between the two. YOu may simpy be missing:
    Private pStartingLocation as Integer
    at the top of the module.
    Everyone who confuses correlation and causation ends up dead.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1