A
ags5406
I'm having a little trouble understanding what is going on in the
following example. It's a simple console app that I built to
illustrate a problem I'm having in a bigger application. I have
sample class Car with property TirePressure() and propery Color. All
four tire pressures are set to 23.0 in the class constructor and the
color is set to Green. But then when I try to change the value of a
particular element of the TirePressure() array in Sub Main(), the code
in Set doesn't seem to execute, but somehow the value in TirePressure
(2) does get changed. However, when I change the value of Color the
code in Set does seem to execute.
In the output window I'd expect to get:
20.0
Oooh_I_Know_I_Know
Blue
Oooh_I_Know_I_Know
But in fact I get:
20.0
I_Dunno
Blue
Oooh_I_Know_I_Know
I put a breakpoint at _TirePressure = value in the Set statement for
TirePressure but the debugger doesn't stop there. I put a breakpoint
at _Color = value in the Set statement for Color but the debugger does
stop there.
Can anyone please explain to me what is going on? Thanks in advance
and my apologies if I've been verbose.
Module Module1
Sub Main()
Dim oCar As New Car
oCar.TirePressure(2) = 20.0
Debug.WriteLine(oCar.TirePressure(2).ToString("0.0"))
Debug.WriteLine(oCar.WasTirePressureChanged.ToString)
oCar.Color = "Blue"
Debug.WriteLine(oCar.Color)
Debug.WriteLine(oCar.WasColorChanged.ToString)
End Sub
End Module
Class Car
Private _TirePressure(3) As Single
Public Property TirePressure() As Single()
Get
Return _TirePressure
End Get
Set(ByVal value As Single())
_TirePressure = value
_WasTirePressureChanged =
PossibleAnswers.Oooh_I_Know_I_Know
End Set
End Property
Private _WasTirePressureChanged As PossibleAnswers
Public ReadOnly Property WasTirePressureChanged() As
PossibleAnswers
Get
Return _WasTirePressureChanged
End Get
End Property
Private _Color As String
Public Property Color() As String
Get
Return _Color
End Get
Set(ByVal value As String)
_Color = value
_WasColorChanged = PossibleAnswers.Oooh_I_Know_I_Know
End Set
End Property
Private _WasColorChanged As PossibleAnswers
Public ReadOnly Property WasColorChanged() As PossibleAnswers
Get
Return _WasColorChanged
End Get
End Property
Public Sub New()
_TirePressure(0) = 23.0
_TirePressure(1) = 23.0
_TirePressure(2) = 23.0
_TirePressure(3) = 23.0
_WasTirePressureChanged = PossibleAnswers.I_Dunno
_Color = "Green"
_WasColorChanged = PossibleAnswers.I_Dunno
End Sub
Public Enum PossibleAnswers
I_Dunno
Oooh_I_Know_I_Know
End Enum
End Class
following example. It's a simple console app that I built to
illustrate a problem I'm having in a bigger application. I have
sample class Car with property TirePressure() and propery Color. All
four tire pressures are set to 23.0 in the class constructor and the
color is set to Green. But then when I try to change the value of a
particular element of the TirePressure() array in Sub Main(), the code
in Set doesn't seem to execute, but somehow the value in TirePressure
(2) does get changed. However, when I change the value of Color the
code in Set does seem to execute.
In the output window I'd expect to get:
20.0
Oooh_I_Know_I_Know
Blue
Oooh_I_Know_I_Know
But in fact I get:
20.0
I_Dunno
Blue
Oooh_I_Know_I_Know
I put a breakpoint at _TirePressure = value in the Set statement for
TirePressure but the debugger doesn't stop there. I put a breakpoint
at _Color = value in the Set statement for Color but the debugger does
stop there.
Can anyone please explain to me what is going on? Thanks in advance
and my apologies if I've been verbose.
Module Module1
Sub Main()
Dim oCar As New Car
oCar.TirePressure(2) = 20.0
Debug.WriteLine(oCar.TirePressure(2).ToString("0.0"))
Debug.WriteLine(oCar.WasTirePressureChanged.ToString)
oCar.Color = "Blue"
Debug.WriteLine(oCar.Color)
Debug.WriteLine(oCar.WasColorChanged.ToString)
End Sub
End Module
Class Car
Private _TirePressure(3) As Single
Public Property TirePressure() As Single()
Get
Return _TirePressure
End Get
Set(ByVal value As Single())
_TirePressure = value
_WasTirePressureChanged =
PossibleAnswers.Oooh_I_Know_I_Know
End Set
End Property
Private _WasTirePressureChanged As PossibleAnswers
Public ReadOnly Property WasTirePressureChanged() As
PossibleAnswers
Get
Return _WasTirePressureChanged
End Get
End Property
Private _Color As String
Public Property Color() As String
Get
Return _Color
End Get
Set(ByVal value As String)
_Color = value
_WasColorChanged = PossibleAnswers.Oooh_I_Know_I_Know
End Set
End Property
Private _WasColorChanged As PossibleAnswers
Public ReadOnly Property WasColorChanged() As PossibleAnswers
Get
Return _WasColorChanged
End Get
End Property
Public Sub New()
_TirePressure(0) = 23.0
_TirePressure(1) = 23.0
_TirePressure(2) = 23.0
_TirePressure(3) = 23.0
_WasTirePressureChanged = PossibleAnswers.I_Dunno
_Color = "Green"
_WasColorChanged = PossibleAnswers.I_Dunno
End Sub
Public Enum PossibleAnswers
I_Dunno
Oooh_I_Know_I_Know
End Enum
End Class