what's wrong in this code in part 2 it should give answer same the solution part 1

Private Sub mnuFileCloce_Click()
End

End Sub

'para1
Private Sub Text1_Change()
Dim K1, K2, K3, K4, K5, K6, K7, K8, K9 As Double
Dim Tc, Pc, T, X, Xx, Xy, Xz, P As Double
K1 = -7.691234564
K2 = -26.08023696
K3 = -168.1706546
K4 = 64.23285504
K5 = -118.9646225
K6 = 4.167117732
K7 = 20.9750676
K8 = 1000000000#
K9 = 6#
Ts = Val(Text1.Text)
Tc = 647.3
Pc = 22120#
T = Ts + 273.15
X = T / Tc
Xx = 1 + K6 * (1 - X) + K7 * (1 - X) ^ 2
Xy = K8 * (1 - X) ^ 2 + K9
Xz = K1 * (1 - X) + K2 * (1 - X) ^ 2 + K3 * (1 - X) ^ 3 + K4 * (1 - X) ^ 4 + K5 * (1 - X) ^ 5
Ps = Pc * Exp(((1 / X) * Xz) / Xx - (1 - X) / Xy)
Text2.Text = Str(Ps)
If Text1.Text = "" Then Text2.Text = ""

If Text4.Text = "" Then Text3.Text = ""

End Sub

'part 2
Private Sub Text4_Change()
Dim K1, K2, K3, K4, K5, K6, K7, K8, K9 As Double
Dim Tc, Pc, T, Ts, X, Xx, Xy, Xz, Ps, P As Double
Dim A1, A2, A3, A4, A5, A6, PDIF As Double

Dim I As Long
A1 = 46.8922631
A2 = 3.61025379
A3 = -0.181752837
A4 = -0.00657409
A5 = -0.010390705
A6 = -0.00228354

K1 = -7.691234564
K2 = -26.08023696
K3 = -168.1706546
K4 = 64.23285504
K5 = -118.9646225
K6 = 4.167117732
K7 = 20.9750676
K8 = 1000000000
K9 = 6
I = 0
Pc = 22120
Ps = Val(Text4.Text)
P1 = (A1 + (A2 * Ps))
P2 = (A3 * Ps ^ 2)
P3 = (A4 * Ps ^ 3)
P4 = (A5 * Ps ^ 4)
P5 = (A6 * Ps ^ 5)
Ts = P1 + P2 + P3 + P4 + P5

30
T = Ts + 273.15
Tc = 647.3

X = T / Tc
Xx = 1 + K6 * (1 - X) + K7 * (1 - X) ^ 2
Xy = K8 * (1 - X) ^ 2 + K9
Xz = K1 * (1 - X) + K2 * (1 - X) ^ 2 + K3 * (1 - X) ^ 3 + K4 * (1 - X) ^ 4 + K5 * (1 - X) ^ 5
P = Pc * Exp((((1 / X) * Xz) / (Xx)) - ((1 - X) / Xy))

PDIF = Ps * 100# / P
If PDIF > 1.0001 Or PDIF < 0.9999 Then
Ts = Ts * ((PDIF) ^ 0.5)
I = I + 1
Label9.Caption = Str(I)
GoTo 30

End If

Text3.Text = Str(Ts)
If Text4.Text = "" Then Text3.Text = ""

End Sub

Recommended Answers

All 6 Replies

First of all, you say you get a different "solution" which is essentially meaningless without knowing what variable contains the solution. Secondly, it's different code so why should you expect the same result(s)?

it should give me the not the same but part1 use for finding Ps by inputing Ts
and part2 use to find Ts by inputing Ps which i mea when the solution part1 most be equal to inpute part2 and the opposite is the same and there is this problem in part 2 when i input number 1 the visual basic programm will freeze it stop working and when i give input 100 it say over flow what wrong here

You lost me at

the opposite is the same

In any case...

  • In part 1 you don't declare Ps.
  • In part 1 you do Ts = Val(Text1.Text)
  • In part 2 you do Ts = P1 + P2 + P3 + P4 + P5
  • In part2 you have a line that says only 30

etc.

I repeat - the code is different. Why do you expect the same results?

I saw that the code is different but what should I say if my teacher say it the solution should be same
I going to be crazy with this code and this program i’m trying so hard with my project its so complicated it related to psychometric chart (properties of air ) my teacher give me this code so as to work in the program but it go wrong so I see I have to find my own code

thanks for helping me Reverend Jim ^_^

If you must use a goto statement you have to mark the line like so:
30:
GoTo 30

Sorry. I saw the "30" by itself and missed the GOTO.Shame on me. Having said that, Never use a GOTO. If you do, then shame on you.

If the teacher gave you code to use then I suggest you use that code. If the GOTO is in your teacher's code then shame on him/her. I suspect your teacher is an engineer (based on the completely undescriptive variable names).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.