473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Question on using "Property"

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
Nov 20 '05 #1
3 1643
* Gary <cr****@montanadsl.net> scripsit:
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


I don't see any reason why your code should not work. Are you sure
there is no other code in your project and really 'Sub Main' is
executed?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2
Gary wrote:
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.


Do you see this behaviour when you just run the program all through, or when
stepping in the debugger. Because in the first case I can't reproduce it,
Calc() gets called only once when I just run the program without ever
breaking.

In the debugger the results you see might make sense if the 'C' property is
in either the "Autos", "Locals" or "Watch" window, because every time the
debugger evaluates C for display in these windows, Calc() gets called if
mUDC=False. The debugger would indeed not step into Calc() when that
happens.

--
Sven Groot

http://unforgiven.bloghorn.com

Nov 20 '05 #3
Hi,

I did indeed have "C" displayed in the "me" window during debug, and
apparently that was the problem, since it works fine when I close the
"me" window, or just run it without debug.

Thanks -- Gary
Gary wrote:
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.

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Guido van Rossum | last post by:
I'm pleased to announce that the Python Software Foundation (PSF) is now accepting donations from individuals and companies interested in supporting our mission to improve the Python programming...
0
by: Luigi | last post by:
I would know what "criteria" is used in box positioning with the position property. Here my tries (using IE and Opera): I have a box with an absolute positioning (properties used: position,...
2
by: Steve Teeples | last post by:
Someone introduced me to PropertyGrid last night. It is a great feature for what I need. A question though. I noticed that when I assign a "TextBox" control to a property grid the description on...
4
by: Bill Coan | last post by:
NOTE: This was posted earlier to vsnet.vstools.office under a different subject line but received no response. I'm having a problem automating Word's Find object from a .NET application, using...
3
by: jbeteta | last post by:
Hello, I have a problem declaring variables. I need to create an object oRpte as ReportClass on WebForm1.aspx and be able to use its value on WebForm2.aspx. For declaring the property oRpte()...
30
by: josh | last post by:
Hi all, what does it meaning that strange sintax (look at the object :) ? if I have i.e. array.length I can use array. and is it IE/Firefox compatible??
3
by: Tom | last post by:
Can someone please explain the non-working aspect of binding to Width? See code below. Thanks !! -- Tom =================================================== using System; using...
5
by: akonsu | last post by:
hello, i need to add properties to instances dynamically during run time. this is because their names are determined by the database contents. so far i found a way to add methods on demand: ...
3
by: Simon van Beek | last post by:
Dear reader, What can be wrong in my ComboBox, the property "Auto Expand" is set to Yes, but by typing in the ComboBox it doesn't expand. Is this because the source of the ComboBox is a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.