p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Stephens' Visual Basic Programming 24-Hour Trainer (http://p2p.wrox.com/forumdisplay.php?f=621)
-   -   Ex 24-3 question (http://p2p.wrox.com/showthread.php?t=85205)

zavodney September 28th, 2011 11:50 PM

Ex 24-3 question
 
I am getting errors while fleshing out the Player class. With my class like this:

Code:

Public Class Player

    ' Declare the Name
    Public Property Name As String

    ' Create the backing variable for Points
    Private _Points As Integer
    ' Define the Points property
    Public Property Points As Integer

    ' Return the Level (Points\10)
    Public ReadOnly Property Level As Integer
        Get

        End Get
    End Property
End Class

I am receiving this error:

"variable '_Points' conflicts with a member implicitly declared for property 'Points' in class 'Player'."

and I do not have the Get and Set procedures created for me.

When I comment out the "Private _Points As Integer" line so I can at least use the automatic creation of the Get and Set procedures I still do not get them. I then created the Level Property and the automatic creation worked fine. I tried the Points Property again and still got nothing. Apparently I am missing something but I cannot figure it out. I am using Visual Studio Express. Help, please. Thank you.

Keith Z.

Rod Stephens September 29th, 2011 09:38 AM

Hi Keith,
"variable '_Points' conflicts with a member implicitly declared for property 'Points' in class 'Player'."
I'm not sure about this but it sounds like it's trying to create auto-generated property procedures for you and it's creating a variable named _Points behind the scenes. Then when you create your variable with that name, it's getting confused because there are two variables with the same name.

(If you're feeling daring, you could peek inside the auto-generated code to see if there's a variable named _Points in there.)

Try commenting out the variable. Then go to the end of the property declaration and press Enter to see if the code editor can make the property get and set procedures. If so, uncomment your variable and you should be back in business.

If that doesn't work, let me know and perhaps email me the project and I'll look more closely.

zavodney September 29th, 2011 01:41 PM

I tried commenting out the _Points line and it didn't help. I put the code in Level.Get to remove the warning and that didn't help. I'll try deleting the class and recreating it just in case something got stuck. If that doesn't work I'll try deleting the whole project and start over. Thank you.

Keith

Rod Stephens September 29th, 2011 02:29 PM

You might also try commenting out the _Points variable. Then refer to _Points somewhere in the code. If it will let you do that, click on that reference and press F12. That should take you to the code that defines the symbol. Perhaps you can figure out where it is squirreled away.

You could also try using the Object Browser (look in the View menu) to see if you can find _Points defined somewhere.

I wonder if it was automatically created somewhere but then forgotten by the development environment so it can only sort of find it now [:confused:]

zavodney September 29th, 2011 08:27 PM

I commented out the _Points declaration and then tried to access it later. Could not access it. I created a new project and the first entry was to declare the Points property. Still no auto creation. I then tried the names PPoints and PlayerPoints and still no auto creation. I then created the Level property and the Get was provided automatically. Both of these properties were integers so I have to assume that I am infringing on some predefined Object. The downloaded code works fine. I didn't see anything in the Object Browser about PlayerPoints. Here's the code I used:

Code:

Public Class Player

    ' Create the Points property
    Public Property PlayerPoints As Integer


    ' This is created after the POINTS property to
    ' see if it works on something else.
    ' Return the Level (Point \ 10)
    Public ReadOnly Property Level As Integer
        Get

        End Get
    End Property

End Class



All times are GMT -4. The time now is 01:42 PM.

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