View Light

Getter/Setter example

Instead of defining tedious, Java-like (.getValue() /.setValue()) getters and setters, it's a lot quicker to just define a property, then use that property in your definition of the class:

' Declaration of private value that will be updated by the
' "Getter/Setter" property code below rather than giving
' direct access to the private variable.
Private _SomeValue as string

' The code is for interacting with the private variable
Public Property SomeValue() As String
    Return _SomeValue ' Use same name with an underscore for the private value
  End Get
  Set(ByVal Value As String)
    _SomeValue = Value
  End Set
End Property

' Setting the value:
Me.User = ""

' Getting the value:
SomethingElse = Me.User

Much cleaner than that archaic Java language!
Rating: (You must be logged in to vote)
This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available in our efforts to advance understanding of environmental, political, human rights, economic, democracy, scientific, and social justice issues, etc. We believe this constitutes a 'fair use' of any such copyrighted material as provided for in section 107 of the US Copyright Law. In accordance with Title 17 U.S.C. Section 107, the material on this site is distributed without profit to those who have expressed a prior interest in receiving the included information for research and educational purposes. For more information go to: . If you wish to use copyrighted material from this site for purposes of your own that go beyond 'fair use', you must obtain permission from the copyright owner.