473,573 Members | 5,087 Online
Bytes | Software Development & Data Engineering Community
+ 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 3164
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!Descript ion: 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!Descript ion 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
4817
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 miss something and width of paragraph can be set less than its content (without overflow specification)? Document is here:...
1
13235
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 style="height:100%;overflow:scroll;/*overflow:-moz-scrollbars-vertical;*/overflow-x:hidden;overflow-y:auto;"> <table style="width:100%;"> which works fine in IE as i want it to, but not in...
13
2811
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
3120
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 (nested), three list views, one tree control with up to 30,000 nodes, maybe 15 comboboxes (half of which have a large recordset as rowsource), 20 or...
4
9039
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. However, it is not as straightforward to determine the base address for my stack space. The approach I have taken is to save the address of an automatic...
4
12887
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 this problem...
8
10654
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 integer scope smaller than MAXINT,so I want to seek a measure to test the excess without the value's comparing to MAXINT. Please let me know if you...
7
22030
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 a; (this type of code and other complex mallc/free etc is used frequently and total approx 450 files, each file is of approx/avg 1000 line,
2
3075
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. ____________________________________________________________________________________ 1) The program should expect 2 decimal integers per line. Let's call these n1 and n2....
0
7792
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...
0
7709
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8091
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5605
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...
0
5296
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...
0
3738
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...
1
2228
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
1
1330
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1049
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...

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.