473,748 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1677
* Gary <cr****@montana dsl.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
2042
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 language. The PSF holds the intellectual property rights for Python and is working towards building a program to fund future Python development. Your donation will make a real difference in the quality of Python's future. For US individuals: ...
0
1530
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, left and top). I noted that if the reference of this box is the "html" box or the "body" box, the browser uses the following rules:
2
3415
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 each property is shown at the bottom of the grid. Also, properties are divided into categories. How can I do this with my own defined objects? For example: I would like Name to be in one category with a description for it and Days to be in...
4
3967
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 late binding. If I use early binding, my code runs fine on most systems, but it is vulnerable to a known bug explained here: http://support.microsoft.com/default.aspx?scid=kb;en-us;292744
3
2266
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() on WebForm1.aspx, I use "Public Property" and I declare variable _oRpte as Friend Shared. That's my problem. If I don't declare _oRpte as Friend Shared, I can't use WebForm1.oRpte() on other webpage. If I declare _oRpte as Friend Shared, I can use...
30
2945
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
1579
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 System.Collections.Generic;
5
14572
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: class A(object) : def __getattr__(self, name) : if name == 'test' : def f() : return 'test'
3
17246
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 query.
0
8996
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9333
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8255
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.