G
Gary
Hi,
In the program below, C = A+B, and the aim is to delay the calculation
of C until the user asks for C. The boolean mUTD (UpToDate) is used
indicate when Calc() must be run to make the C = A+B calculation before
C is returned to user.
When the Driver program at bottom is run, the behavior is very strange,
the debug statement "in Calc" gets printed several times on entry to the
constructor, and then again several times when T.A = 1 is executed, and
again several times when T.B = 2 is executed (a grand total of 30 times
for the full execution of Driver. When you step through, the debugger
never actually takes you into Calc() -- you just see the "in calc nn"
printed in output window.
I am using Visual Basic.net, version 2003, Windows XP Pro on a Dell.
I am apparently not understanding something about Property?? or ??
Help!!
Public Class TestCls
Private mA As Double
Private mB As Double
Private mC As Double
Private mUTD As Boolean = False
Private Count As Integer = 0
Property A() As Double
Get
Return mA
End Get
Set(ByVal Value As Double)
mA = Value
mUTD = False
End Set
End Property
Property B() As Double
Get
Return mB
End Get
Set(ByVal Value As Double)
mB = Value
mUTD = False
End Set
End Property
ReadOnly Property C() As Double
Get
If Not mUTD Then Calc()
Return mC
End Get
End Property
Public Sub New()
mUTD = False
End Sub
Private Sub Calc()
mUTD = True
mC = mA + mB
Count = Count + 1
Debug.WriteLine("In Calc " & Count.ToString)
End Sub
End Class
----------------- Driver Program ----
Module TestDrive
Sub Main()
Dim T As New TestCls
Dim xx As Double
T.A = 1
T.B = 2
xx = T.C
End Sub
End Module
Thanks -- Gary
In the program below, C = A+B, and the aim is to delay the calculation
of C until the user asks for C. The boolean mUTD (UpToDate) is used
indicate when Calc() must be run to make the C = A+B calculation before
C is returned to user.
When the Driver program at bottom is run, the behavior is very strange,
the debug statement "in Calc" gets printed several times on entry to the
constructor, and then again several times when T.A = 1 is executed, and
again several times when T.B = 2 is executed (a grand total of 30 times
for the full execution of Driver. When you step through, the debugger
never actually takes you into Calc() -- you just see the "in calc nn"
printed in output window.
I am using Visual Basic.net, version 2003, Windows XP Pro on a Dell.
I am apparently not understanding something about Property?? or ??
Help!!
Public Class TestCls
Private mA As Double
Private mB As Double
Private mC As Double
Private mUTD As Boolean = False
Private Count As Integer = 0
Property A() As Double
Get
Return mA
End Get
Set(ByVal Value As Double)
mA = Value
mUTD = False
End Set
End Property
Property B() As Double
Get
Return mB
End Get
Set(ByVal Value As Double)
mB = Value
mUTD = False
End Set
End Property
ReadOnly Property C() As Double
Get
If Not mUTD Then Calc()
Return mC
End Get
End Property
Public Sub New()
mUTD = False
End Sub
Private Sub Calc()
mUTD = True
mC = mA + mB
Count = Count + 1
Debug.WriteLine("In Calc " & Count.ToString)
End Sub
End Class
----------------- Driver Program ----
Module TestDrive
Sub Main()
Dim T As New TestCls
Dim xx As Double
T.A = 1
T.B = 2
xx = T.C
End Sub
End Module
Thanks -- Gary