Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   .NET General (http://www.xtremevbtalk.com/-net-general/)
-   -   Public Property Expresion Expected (http://www.xtremevbtalk.com/-net-general/328716-public-property-expresion-expected.html)

JeremyBenson11 08-16-2017 08:14 AM

Public Property Expresion Expected
 
Hello,

I'm getting an error expression expected when trying to set a public property, but can't seem to find the error. Thanks for reading.

Class
Code:

Public Class World
        Public Property currentRoom() As String
                Get
                        Return Me.currentRoom
                End Get
                Set(ByVal value As String)
                        Me.currentRoom = value
                End Set
        End Property
        Public Property currentRegion() As String
                Get
                        Return Me.currentRegion
                End Get
                Set(ByVal value As String)
                        Me.currentRegion = value
                End Set
        End Property
End Class

Program
Code:

Module Program
        Sub Main()
                Dim world As World = New World()
                world.currentRoom = 'Bedroom'
                Console.Write("Press any key to continue . . . ")
                Console.ReadKey(True)
        End Sub
End Module


Goggy 08-16-2017 08:20 AM

both your properties are recursively setting them self.

Code:

Public Property X() As String
                Get
                        Return Me.X
                End Get
                Set(ByVal value As String)
                        Me.X = value
                End Set
        End Property

To sove this, try some thing like the following


Code:

Private m_X as String

Public Property X() As String
                Get
                        Return Me.m_X
                End Get
                Set(ByVal value As String)
                        Me.m_X = value
                End Set
        End Property


JeremyBenson11 08-16-2017 10:00 AM

Still getting the same error, I added to lines to my main program, and both are getting the error. Maybe some kind of typo?

Code:

Public Class World
        Private currentRoom As String
        Private currentRegion As String
        Public Property room() As String
                Get
                        Return Me.currentRoom
                End Get
                Set(ByVal value As String)
                        Me.currentRoom = value
                End Set
        End Property
        Public Property region() As String
                Get
                        Return Me.currentRegion
                End Get
                Set(ByVal value As String)
                        Me.currentRegion = value
                End Set
        End Property
End Class

Code:

Module Program
        Sub Main()
                Dim world As World = New World()
                world.room = 'Bedooroom'
                world.region = 'Alm'
                Console.Write("Press any key to continue . . . ")
                Console.ReadKey(True)
        End Sub
End Module


Goggy 08-16-2017 11:20 AM

world.room = 'Bedooroom'
world.region = 'Alm'

Here's the typo, vb doesn't use single quotes for a a string but double, like so...

Code:

        world.room = "Bedooroom"
        world.region = "Alm"



All times are GMT -6. The time now is 06:10 PM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.