I've been trying to get an answer as to why this is happening from different forums on the net and as of yet no one has been able to tell me why it happens or how to fix it. Here is the situation:
Basically, in one of my get methods:
Code:
Property Get H() As Double
H = CalcH 'This was implemented as the "Back Way" and it fixed problem, before the code in CalcH was in here
End Property
Private Function CalcH() As Double
If pH <= 0# And pT > 0# And pP > 0# Then 'calculate if not set
pH = STMPTH(pP, pT)
ElseIf pH <= 0# And pT > 0# Then
If pType = StreamType.Water Then
pH = STMTQH(pT, 0#)
Else
pH = STMTQH(pT, 1#)
End If
ElseIf pH <= 0# And pP > 0# Then
If pType = StreamType.Water Then
pH = STMPQH(pP, 0#)
Else
pH = STMPQH(pP, 1#)
End If
End If
CalcH = pH
End Function
When I run the program, I give pH a value of 1488. But when it comes to retrieving that value the compiler goes nuts. If I run the program, I get "Error 6: Overflow". So I use the debugger, I step through the WHOLE program... and it completes its run with no issue.... so I run again... and get the error. I find out it is when I retrieve the H value. So I put a break right there. I run program to the break and then step through the retrieval and find something quite odd. When it gets to the
Code:
If pH <= 0# And pT > 0# And pP > 0# Then 'calculate if not set
it actually returns true... but pH has a value of 1488! so I do this again and mouse over the pH to see what it says and it says "pH = 0" thats odd... I hit F8 to step. then mouse over pH, still "pH = 0" I open up the locals window and locate the pH variable. it says "pH = 1488", I mouse over pH again and now it says "pH = 1488" BUT IT JUST PASSED AN IF STATEMENT SAYING IF<=0!!!! please help!
Screenshots (in order):
1
2
3
4
5
6
7
Here is the rest of the class (omited CalcH due to its already posted)
Code:
Private pP As Double 'Pressure of the stream
Private pT As Double 'Temperature of the stream
Private pH As Double 'Enthalpy of the stream
Private pW As Double 'Flow of the stream
Private pType As StreamType 'Type of stream: Steam, Water, Leak(Enum)
Private pName As String 'Name of the stream
Property Let P(P As Double)
pP = P
End Property
Property Let T(T As Double)
If pType = Steam And pP <> 0 Then
If (T - STMPT(pP)) < 27 Then 'Check for 27 degree superheat per PTC 6
pT = 0
Else
pT = T
End If
Else
pT = T
End If
End Property
Property Let H(H As Double)
pH = H
End Property
Property Let W(W As Double)
pW = W
End Property
Property Get P() As Double
P = pP
End Property
Property Get T() As Double
If pT = 0 And pH > 0 And pP > 0 Then 'calculate if temp unknown & H known
If Not SuperHeat Then
pT = STMPHT(pP, pH)
End If
End If
T = pT
End Property
Property Get H() As Double
H = CalcH
End Property
Property Get W() As Double
W = pW
End Property
Property Get SType() As StreamType
SType = pType
End Property
Property Get Name() As String
Name = pName
End Property
Property Get S() As Double 'Get Entropy
If pT <> 0 And pP <> 0 Then
S = STMPTS(pP, pT)
ElseIf pT = 0 And pP <> 0 Then
S = STMPHS(pP, H)
End If
End Property
Property Get x() As Double 'Get X
x = STMPHQ(pP, H)
End Property
Property Get Q() As Double 'Get Energy Flow Rate (H*W)
Q = H * pW
End Property
Property Get V() As Double 'Get Specific Volume
V = STMPTV(P, T)
End Property
Property Get Density() As Double 'Get Specific Density
If P = 0 Then
Density = 62.087 + 0.022519 * T - 0.00033873 * (T ^ 2) + 0.0000010579 * (T ^ 3)
Else
Density = 1 / V
End If
End Property
Property Get C() As Double 'Get Specific Heat
C = 1.0244 - 0.00071715 * pT + 0.0000061796 * (pT ^ 2) - 0.000000016397 * (pT ^ 3)
End Property
This problem went away. And KEEPS COMING BACK!!! I switched my computers out and it started working again. Now I have the same sort of issue and we tried it on 3 different computers here. same problem. I run the program and get overflow. but I can hold down F8 for 20 minutes and easily fly past the point at which it crashes. I am so tired of it. I want to use C# or C++ but unfortunately my company does not have licenses for it.