I've tried it in my program (set validation not exceed 100)
====================================
Private mlVARIABLE As Integer
Public Property _mlVARIABLE() As Integer
Get
Return mlVARIABLE
End Get
Set(ByVal Value As Integer)
If Value > 100 Then
Throw New Exception("tidak kurang dari 100")
Else
mlVARIABLE = Value
End If
End Set
End Property
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
mlVARIABLE = 200
mSomeVariable = 153
End Sub
====================================
But when I assign mlVARIABLE = 200, it just goes through without any
validation message. Why ?
"_AnonCoward" <ab*@xyz.com> wrote in message
news:nj*********************@twister.southeast.rr. com...
"Kalim Julia" <ka*********@gmail.com> wrote in message
news:OC**************@TK2MSFTNGP12.phx.gbl...
: Anybody can explain me what is
: 1. Get ..... EndGet
: 2. Set ...... EndSet
:
: Please send me any example.
They relate to properties.
As an example, say you have a variable in your class that you want to
expose. Users are allowed full access to read the variable, but you don't
want users to give the variable a value greater than 100. If you make the
variable public, users can assign any value at all to it. By using a
property however, you can trap invalid values.
----------------------------------
Private mSomeVariable As Integer
Public Property SomeVariable() As Integer
Get
Return mSomeVariable
End Get
Set '(input parameter 'value' implied)
If value > 100 Then
Throw New Exception("value cannot exceed 100")
Else
mSomeVariable = value
End If
End Set
End Property
----------------------------------
Another use would be if you want to allow users to see the value of the
variable but do not want them to be able to change it. A 'read only'
property allows that.
----------------------------------
Private mSomeVariable
Public Readonly Property SomeVariable
Get
Return mSomeVariable
End Get
End Property
----------------------------------
Ralf
--
--
----------------------------------------------------------
* ^~^ ^~^ *
* _ {~ ~} {~ ~} _ *
* /_``>*< >*<''_\ *
* (\--_)++) (++(_--/) *
----------------------------------------------------------
There are no advanced students in Aikido - there are only
competent beginners. There are no advanced techniques -
only the correct application of basic principles.