473,467 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Overflow (Not a newbie question) VBA

13 New Member
First, let me start by saying I know what an overflow is (Too large of a value into something that can't hold it, i.e. 35000 into an int, or 0/0, etc).

Now to the issue. I have a class that I am trying to apply a value to one of its properties.

Expand|Select|Wrap|Line Numbers
  1. ...
  2. Streams.Item(rsName!Description).HInput = STMPTH(rs!P, rs!T)
  3. ...
  4.  
  5. <in class>
  6. Property Let HInput(HInput As Double) 'Set the Enthalpy Input Value
  7.     pHInput = HInput
  8.     pH = pHInput
  9. End Property
  10.  
where STMPTH() is a Steam Table look up method that takes a Double P and Double T and returns a Double H (Pressure, Temperature, return Enthalpy)

There are over 100 items in the Streams collection and only 2 throw an over flow error at the first line of code I have put up here. Now, before you ask, I do not have access to the code of the STMPTH() method (it's in a DLL file that my company did not create). However, I know the method does work. When the overflow error is thrown, the compiler stops on that line:

Expand|Select|Wrap|Line Numbers
  1. Streams.Item(rsName!Description).HInput = STMPTH(rs!P, rs!T)
  2.  
So, I decide to use Step Through (F8) to try to debug the issue (thinking maybe I'm passing a negative value or something). But when I hit F8, the program continues without a hitch.

This is far from the first time I encountered this "phenomena" and have worked around it previously by catching the error and retrying the calculation (which worked. Example:

Expand|Select|Wrap|Line Numbers
  1. Property Get H() As Double 'Return Enthalpy of Stream
  2.     H = 0
  3.     On Error GoTo HErr
  4.     If pSameAs = "" Then
  5.         If pH <= 0 Then 'Enthalpy Not Known
  6.             If pT > 0# And pP > 0# Then 'Calculate From Pressure and Temperature
  7.                 pH = STMPTH(pP, pT)
  8.             ElseIf pT > 0# Then
  9.                 If pType = STREAMTYPE.Water Then
  10.                     pH = STMTQH(pT, 0#)
  11.                 End If
  12.             ElseIf pP > 0# Then
  13.                 If pType = STREAMTYPE.Water Then
  14.                     pH = STMPQH(pP, 0#)
  15.                 End If
  16.             End If
  17.         End If
  18.     Else
  19.         pH = Streams(pSameAs).H
  20.     End If
  21.     H = pH
  22.     GoTo HExit
  23. HErr:
  24.     H = 0
  25.     pT = pT
  26.     pP = pP
  27.     If pSameAs = "" Then
  28.         If pH <= 0 Then 'Enthalpy Not Known
  29.             If pT > 0# And pP > 0# Then 'Calculate From Pressure and Temperature
  30.                 pH = STMPTH(pP, pT)
  31.             ElseIf pT > 0# Then
  32.                 If pType = STREAMTYPE.Water Then
  33.                     pH = STMTQH(pT, 0#)
  34.                 Else
  35.                     pH = STMTQH(pT, 1#)
  36.                 End If
  37.             ElseIf pP > 0# Then
  38.                 If pType = STREAMTYPE.Water Then
  39.                     pH = STMPQH(pP, 0#)
  40.                 Else
  41.                     pH = STMPQH(pP, 1#)
  42.                 End If
  43.             End If
  44.         End If
  45.     Else
  46.         pH = Streams(SameAs).H
  47.     End If
  48.     H = pH
  49. HExit:
  50. End Property
  51.  
However, this little "work around" does not want to work in this case and I am now at a loss as to how to fix this.

I have seen a couple of posts from other people on some forums with the same issue but they work around it by changing languages or compilers. I am limited to using VBA in access and am getting extremely frustrated with this problem.

Does anyone know of a solution?

Oh and I am using MS Access 2000 9.0.8961 SP-3
Mar 4 '08 #1
8 3146
FishVal
2,653 Recognized Expert Specialist
Hi, Tophurious.

Actually I'm somewhat confused with the code of H get property.
You check variable pSameAs and if it is empty string do calculations otherwise you call the same property in other instance of the class which may or may not call the same in another instance.
Could you explain the logic?
Could it be so that the property at certain conditions becomes recursive?

Regards,
Fish.
Mar 4 '08 #2
Tophurious
13 New Member
The Get H Property is not where the issue is. That is an example of my work around. the problem is in the first part.

As far as the sameas that simply checks to see if we had set that item's enthalpy to be equal to another item's. if it is use the other items. if not calculate.

And if you notice the overflow error is not occurring on the Get H Property it is occuring in the Set HInput Property (which is included at the top)

Other clarifications:

Dims:
pH: Double (private local)
pHInput: Double (private local)
rsName!Description: String (holds the key of item in collection)
rs!P: Double (pulled from database table, defined as double)
rs!T: Double (pulled from database table, defined as double)
Mar 4 '08 #3
FishVal
2,653 Recognized Expert Specialist
One more stupid question. Sorry.
STMPQH() function is in the same DLL, isn't it?
Did the code of H get property (before you've made the patch) throw the error when try to call particularly it?
Mar 4 '08 #4
Tophurious
13 New Member
STMPQH() also in the DLL (Pressure, Quality, return Enthalpy). I do not remember if that was one that threw an error or not. The issue is not calling these methods.

The previous issue was that the compiler would "forget" the value until you looked at it (that is the best way I can explain it). Basically, the run would throw an overflow and break. I would hover over the variable (say for example, pH) and the tooltip would say "pH = 0" even though I KNEW it wasn't so I would look at the local properties window and in there it would say pH = 1200 (or something). I go and hover over the variable again and it would say "pH = 1200" (This is still in break mode, so the variables shoule not have changed at all) Thats what I mean by "Forget".

The current issue, is not that it is forgetting the value, it just throws an overflow. So I click run, when it hits that line (for only 2 out of the 100+ items in the collection) it throws an overflow and breaks. I click F8 to go forward and it works. Both rs!P and rs!T show proper values in break mode.

To Summarize: Current Issue:
Run == Overflow Error
Step Through == A'OK!!!
Mar 4 '08 #5
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi. You mention that the compiler stops at this line:
Expand|Select|Wrap|Line Numbers
  1. Streams.Item(rsName!Description).HInput = STMPTH(rs!P, rs!T)
VBA passes values by reference by default (as pointers). You are passing recordset field references, which are not updatable, and should only be passed by value, not by reference. Unless the function headers define that these variables are indeed passed by value (which you won't know for STMPTH as it isn't yours) this can cause overflow and other errors if the internal function code tries to change the value (for example, by incrementing it or setting it to another value as a shortcut).

I would suggest you assign the recordset fields to local variables and use these within the function calls instead.

-Stewart
Mar 4 '08 #6
Tophurious
13 New Member
Nice suggestion but nope.

put this in:
Expand|Select|Wrap|Line Numbers
  1. P = CDbl(rs!P)
  2. T = CDbl(rs!T)
  3. Streams.Item(rsName!Description).HInput = STMPTH(P, T)
  4.  
same error, same spot. I had attempted this in my previous issue and it did not resolve it either. Still tried (hell I tried everything else I can think of)

Just so you know, here is the thread I started back in june or july with my original issue (and no one could give me an answer then either)
Here
Mar 4 '08 #7
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Nice suggestion but nope.

put this in:
Expand|Select|Wrap|Line Numbers
  1. P = CDbl(rs!P)
  2. T = CDbl(rs!T)
  3. Streams.Item(rsName!Description).HInput = STMPTH(P, T)
  4.  
same error, same spot. I had attempted this in my previous issue and it did not resolve it either. Still tried (hell I tried everything else I can think of)
OK. And you are certain that you are passing by value
rsName!Description in your streams call? Funnily enough it is with strings that I've had the overflow error when accidentally passing literals by reference.
-Stewart
-Stewart
Mar 4 '08 #8
FishVal
2,653 Recognized Expert Specialist
Actually I'm not so sure that variable values you see in debug mode are the same as at runtime.

I've made a little experiment.

Code module
Expand|Select|Wrap|Line Numbers
  1. Public Sub Test()
  2.     Dim objClass1 As New Class1
  3.     objClass1.q = 1
  4. End Sub
  5.  
Class module: Class1
Expand|Select|Wrap|Line Numbers
  1. Private lngQ As Long
  2.  
  3. Public Property Get q() As Variant
  4.     lngQ = lngQ + 1
  5.     q = lngQ
  6. End Property
  7.  
  8. Public Property Let q(ByVal vNewValue As Variant)
  9.     Err.Raise 9999
  10. End Property
  11.  
You see Get property is never invoked in code and Let property simply throws a error, but the value of lngQ as well as q in locals window constantly increments when going into debug mode. That makes evidence that locals window invokes Get q() property to refresh itself.

I would suggest to get real runtime values of the variables. And maybe you'll need to code several attempts on the unstable code until you get a right value.

Regards,
Fish
Mar 4 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Andrew Fedoniouk | last post by:
I have a simple test document which produce the following in Mozilla and Opera: http://terrainformatica.com/w3/p2/problem1.png Internet Explorer behaves as per recommendation (I guess) Did I...
1
by: Marek Mänd | last post by:
I have question regarding CSS overflow atribute. <body> <table style="height:100%" id="pagetable"> <td style="vertical-align:top;"> <div...
13
by: Ioannis Vranos | last post by:
If we want our programs to be protected against buffer overflows, must we check the size of the various containers explicitly? E.g. #include <iostream> #include <string> int main()
19
by: Jim | last post by:
I have spent the past few weeks designing a database for my company. The problem is I have started running into what I believe are stack overflow problems. There are two tab controls on the form...
4
by: Victor | last post by:
Hello, I've got a situation in which the number of (valid) recursive calls I make will cause stack overflow. I can use getrlimit (and setrlimit) to test (and set) my current stack size. ...
4
by: Chua Wen Ching | last post by:
Thanks Derek... Okay i had another question.. my program runs smoothly for the first minute, after 1 minute... suddenly it breaks and display this error: do you know what is the cause of...
8
by: starffly | last post by:
In my program, the caculated value is supposed to be no more than the constant named MAXINT,otherwise, overflow error will be informed.however, I cannot test if the value exceeds MAXINT within the...
7
by: amit.atray | last post by:
Environement : Sun OS + gnu tools + sun studio (dbx etc) having some Old C-Code (ansi + KR Style) and code inspection shows some big size variable (auto) allocated (on stack) say for ex. char...
2
by: jou00jou | last post by:
Hi, I have trouble using sscanf and fgets to check for overflow. I will post the assignment specification so I could help whoever would kindly like to offer his/her help. ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.