Get and set

  • Thread starter Thread starter Yomus
  • Start date Start date
Hi,

Private _mytest As String

Public Property MyTest() As String
Get
Return _mytest
End Get
Set(ByVal Value As String)
_mytest = Value
End Set
End Property


Regards,
Josip Habjan, Croatia
URL: www.habjansoftware.com
 
Josip Habjan said:
Hi,

Private _mytest As String

Public Property MyTest() As String
Get
Return _mytest
End Get
Set(ByVal Value As String)
_mytest = Value
End Set
End Property


Regards,
Josip Habjan, Croatia
URL: www.habjansoftware.com

Explanation:

The Get and Set keywords are used for properties. The "Getter" is the Get
keyword (statement??) that should always return the value for the property.
The "Setter" is the Set keyword (statement??) that should always set the
value of the property. There are also instances where there would be no
set/get. In these instances, you would use another keyword on the property,
as described below:

Private mUserName As String
Private mPassword As String

Public ReadOnly Property UserName() As String
Get
Return mUserName
End Get
End Property

Public WriteOnly Property Password() As String
Set
mUserName = Value
End Set
End Property

Extra Note:

You do not need the parameter list for the Set like most programmers use.
This extra bit is for clarity I believe but I do not use it as it means
typing more ;)

Set (ByVal Value As String)
mUserName = Value
End Set

gets the same results as

Set
mUserName = Value
End Set

HTH,

Mythran
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top