Private Sub CommandButton1_Click() ' inputs required If cmb1.Text = "" Or cmbt.Text = "" Or cmbp.Text = "" Then MsgBox "Please Check Your Inputs", vbExclamation, "Inputs Error" Me.txt1.SetFocus Exit Sub End If ' in case the user didnt enter numbers If txt1 = "" Then txt1.Value = 0 End If If txt2 = "" Then txt2.Value = 0 End If If txt3 = "" Then txt3.Value = 0 End If If txt4 = "" Then txt4.Value = 0 End If If txt5 = "" Then txt5.Value = 0 End If If txt6 = "" Then txt6.Value = 0 End If If txt7 = "" Then txt7.Value = 0 End If If txt8 = "" Then txt8.Value = 0 End If If txt9 = "" Then txt9.Value = 0 End If If txt10 = "" Then txt10.Value = 0 End If If txt11 = "" Then txt11.Value = 0 End If If txt12 = "" Then txt12.Value = 0 End If ' Pci pc1 = 673 pc2 = 708 pc3 = 617 pic4 = 527 pnc4 = 551 pic5 = 490.4 pnc5 = 485 pc6 = 434 pc7 = 372 pchs = 1306 pcco = 1071 pcn = 493 ' Tci tc1 = 343.5 tc2 = 550.1 tc3 = 666.2 tnc4 = 765.6 tic4 = 733.6 tnc5 = 847 tic5 = 828.7 tc6 = 914.6 tc7 = 1082 tchs = 672.37 tcco = 547.57 tcn = 227.29 ' pc&tc pc = (pcn * txt12.Value) + (pcco * txt11.Value) + (pchs * txt10.Value) + (pc1 * txt1.Value) + (pc2 * txt2.Value) + (pc3 * txt3.Value) + (pic4 * txt4.Value) + (pnc4 * txt5.Value) + (pic5 * txt6.Value) + (pnc5 * txt7.Value) + (pc6 * txt8.Value) + (pc7 * txt9.Value) tc = (tcn * txt12.Value) + (tcco * txt11.Value) + (tchs * txt10.Value) + (tc1 * txt1.Value) + (tc2 * txt2.Value) + (tc3 * txt3.Value) + (tic4 * txt4.Value) + (tnc4 * txt5.Value) + (tic5 * txt6.Value) + (tnc5 * txt7.Value) + (tc6 * txt8.Value) + (tc7 * txt9.Value) ' correction Dim hsps As String Dim hsp As Double hsps = txt10.Text hsp = Val(hsps) Dim cops As String Dim cop As Double cops = txt11.Text cop = Val(cops) Dim asn As Double Dim asns As String asn = hsp + cop asns = Str(asn) bs = txt10.Value eps = (120 * ((asns ^ 0.9) - (asns ^ 1.6))) + (15 * ((bs ^ 0.5) - (bs ^ 4))) tcc = tc - eps pcc = (pc * tcc) / (tc + (bs * (1 - bs) * eps)) ' ppr&tpr p = txtp.Value tt = txtt.Value If cmbp.Text = ("Atm") Then p = txtp.Value * 14.7 End If If cmbt.Text = ("Fahrenhite") Then tt = txtt.Value + 460 End If ppr = p / pcc tpr = tt / tcc 'Papay Method If cmb1.Text = ("Papay") Then zp = 1 - (ppr / tpr) * (0.36748758 - 0.04188423 * (ppr / tpr)) txtan1 = zp ' to display the results in the excel sheet to use them in the graph Do Until p < 0 Cells(12 + i, 4) = p Cells(12 + i, 5) = zp p = p - 50 ppr = p / pcc zp = 1 - (ppr / tpr) * (0.36748758 - 0.04188423 * (ppr / tpr)) i = i + 1 Loop ' display the graph for results Set CurrentChart = Sheets("Charts").ChartObjects(1).Chart CurrentChart.Parent.Width = 426 CurrentChart.Parent.Height = 252 ' Save chart as GIF Fname = ThisWorkbook.Path & Application.PathSeparator & "temp.gif" CurrentChart.Export Filename:=Fname, FilterName:="GIF" ' Show the chart img1.Picture = LoadPicture(Fname) End If ' Hall-Yarborough method If cmb1.Text = ("Hall-Yarborough") Then t = 1 / tpr Dim y As Double Dim yn As Double r = 1 y = 0.0125 * ppr * t * Exp(-0.12 * ((1 - t) ^ 2)) Do Until r <= 0.00001 aa = -0.06125 * ppr * t * Exp(-1.2 * ((1 - t) ^ 2)) ab = (y + (y ^ 2) + (y ^ 3) + (y ^ 4)) / ((1 - y) ^ 3) ac = (y ^ 2) * ((14.76 * t) - (9.76 * (t ^ 2)) + (4.58 * (t ^ 3))) os = (2.18 + (2.82 * t)) ad = (y ^ os) * ((90.7 * t) - (242.2 * (t ^ 2) + (42.4 * (t ^ 3)))) fy = aa + ab - ac + ad ba = (1 + (4 * y) + (4 * (y ^ 2)) - (4 * (y ^ 3)) - (y ^ 4)) / ((1 - y) ^ 4) bb = ((29.52 * t) - (19.52 * (t ^ 2)) + (9.16 * (t ^ 3))) * y bc = (2.18 + 2.82 * t) * (y ^ (1.18 + (2.82 * t))) * ((90.7 * t) - (242.2 * (t ^ 2) + (42.4 * (t ^ 3)))) dfy = ba - bb + bc yn = y - (fy / dfy) r = Abs((yn ^ 2) - (y ^ 2)) y = yn Loop Zh = ((0.06125 * ppr * t / y) * Exp(-1.2 * (1 - t) ^ 2)) txtan2 = Zh Do Until p < 0 Cells(10 + i, 17) = p Cells(10 + i, 18) = Zh p = p - 50 ppr = p / pcc Zh = ((0.06125 * ppr * t / y) * Exp(-1.2 * (1 - t) ^ 2)) i = i + 1 Loop Set CurrentChart = Sheets("Charts").ChartObjects(1).Chart CurrentChart.Parent.Width = 426 CurrentChart.Parent.Height = 252 ' Save chart as GIF Fname = ThisWorkbook.Path & Application.PathSeparator & "temp.gif" CurrentChart.Export Filename:=Fname, FilterName:="GIF" ' Show the chart img1.Picture = LoadPicture(Fname) End If ' Dranchuk and Abu-Kassem method If cmb1.Text = ("Dranchuk and Abu-Kassem") Then a1 = 0.3265 a2 = -1.07 a3 = -0.5339 a4 = 0.01569 a5 = -0.05165 a6 = 0.5375 a7 = -0.7361 a8 = 0.1844 a9 = 0.1056 a10 = 0.6134 a11 = 0.721 r = 1 zd = 1 Do Until r < 0.0001 rho = (0.27 * ppr) / (zd * tpr) ca = (a1 + (a2 / tpr) + (a3 / (tpr ^ 3)) + (a4 / (tpr ^ 4)) + (a5 / (tpr ^ 5))) * rho cb = (a6 + (a7 / tpr) + (a8 / (tpr ^ 2))) * (rho ^ 2) cc = (a9 * (rho ^ 5) * ((a7 / tpr) + (a8 / (tpr ^ 2)))) cd = (a10 * (1 + (a11 * (rho ^ 2))) * ((rho ^ 2) / (tpr ^ 3)) * Exp((-a11 * (rho ^ 2)))) + 1 zn = ca + cb - cc + cd r = Abs((zn ^ 2) - (zd ^ 2)) zd = zn Loop txtan3 = zd Do Until p < 0 Cells(10 + i, 19) = p Cells(10 + i, 20) = zd p = p - 50 ppr = p / pcc zd = ca + cb - cc + cd i = i + 1 Loop Set CurrentChart = Sheets("Charts").ChartObjects(1).Chart CurrentChart.Parent.Width = 426 CurrentChart.Parent.Height = 252 ' Save chart as GIF Fname = ThisWorkbook.Path & Application.PathSeparator & "temp.gif" CurrentChart.Export Filename:=Fname, FilterName:="GIF" ' Show the chart img1.Picture = LoadPicture(Fname) End If ' Dranchuk-Purvis-Robinson method If cmb1.Text = ("Dranchuk-Purvis-Robinson") Then a1 = 0.31506237 a2 = -1.0467099 a3 = -0.57832729 a4 = 0.53530771 a5 = -0.61232032 a6 = -0.10488813 a7 = 0.68157001 a8 = 0.68446549 r = 1 zdp = 1 Do Until r < 0.0001 rho = (0.27 * ppr) / (zdp * tpr) da = 1 + (a1 + (a2 / tpr) + (a3 / (tpr ^ 3))) * rho dbb = (rho ^ 2) * (a4 + (a5 / tpr)) dc = (rho ^ 5) * (a5 * a6 / tpr) dd = (((a7 / (tpr ^ 3)) * (rho ^ 2)) * (1 + (a8 * (rho ^ 2))) * Exp((-a8 * (rho ^ 2)))) zdpn = da + dbb + dc + dd r = Abs((zdpn ^ 2) - (zdp ^ 2)) zdp = zdpn Loop txtan4 = zdp Do Until p < 0 Cells(10 + i, 21) = p Cells(10 + i, 22) = zdp p = p - 50 ppr = p / pcc zd = zdp = da + dbb + dc + dd i = i + 1 Loop Set CurrentChart = Sheets("Charts").ChartObjects(1).Chart CurrentChart.Parent.Width = 426 CurrentChart.Parent.Height = 252 ' Save chart as GIF Fname = ThisWorkbook.Path & Application.PathSeparator & "temp.gif" CurrentChart.Export Filename:=Fname, FilterName:="GIF" ' Show the chart img1.Picture = LoadPicture(Fname) End If ' Hankinson-Thomas-Phillips method If cmb1.Text = ("Hankinson-Thomas-Phillips") Then t = 1 / tpr If ppr < 5 Then a1 = 0.001290236 a2 = 0.38193005 a3 = 0.022199287 a4 = 0.12215481 a5 = -0.015674794 a6 = 0.027271364 a7 = 0.023834219 a8 = 0.4361778 ElseIf ppr >= 5 Then a1 = 0.0014507882 a2 = 0.37922269 a3 = 0.024181399 a4 = 0.11812287 a5 = 0.037905663 a6 = 0.19845016 a7 = 0.048911693 a8 = 0.0631425417 End If Dim zht As Double Dim zhtn As Double r = 1 zht = 0.0125 * ppr * t * Exp(-0.12 * ((1 - t) ^ 2)) Do Until r < 0.0001 aaa = ((1 / zht) - 1) + ((a4 * tpr) - a2 - (a6 / tpr ^ 2) * (ppr / (zht ^ 2) * (tpr ^ 2))) bbb = ((a3 * tpr) - a1) * ((ppr ^ 2) / (zht ^ 3) * (tpr ^ 3)) ccc = (a1 * a5 * a7 * (ppr ^ 2) / ((zht ^ 6) * (tpr ^ 6))) * (1 + (a8 * (ppr ^ 2)) / ((zht ^ 2) * (tpr ^ 2))) * Exp((-a8 * (ppr ^ 2)) / ((zht ^ 2) * (tpr ^ 2))) fzht = aaa + bbb + ccc ddd = ((-a6 * ppr) / (zht ^ 2)) + (a4 * tpr) - a2 + (1 / zht) - 1 eee = ((ppr ^ 2) * (tpr ^ 2) * ((a3 * tpr) - a1)) / (zht ^ 3) fff = ((2.718 ^ (a8 * (ppr ^ 2)) / ((tpr ^ 2) * (zht ^ 2))) * (1 + (a8 * (ppr ^ 2) / ((tpr ^ 2) * (zht ^ 2))) * (a7 * a5 * a1 * (ppr ^ 2)))) / ((tpr ^ 6) * (zht ^ 6)) dfzht = ddd + eee + fff zhtn = zht - (fzht / dfzht) r = Abs((zhtn ^ 2) - (zht ^ 2)) zht = zhtn Loop txtan5 = zht Do Until p < 0 Cells(10 + i, 23) = p Cells(10 + i, 24) = zht p = p - 50 ppr = p / pcc zht = aaa + bbb + ccc i = i + 1 Loop Set CurrentChart = Sheets("Charts").ChartObjects(1).Chart CurrentChart.Parent.Width = 426 CurrentChart.Parent.Height = 252 ' Save chart as GIF Fname = ThisWorkbook.Path & Application.PathSeparator & "temp.gif" CurrentChart.Export Filename:=Fname, FilterName:="GIF" ' Show the chart img1.Picture = LoadPicture(Fname) End If End Sub ' clear papay line from graph Private Sub CommandButton11_Click() Cells(12, 4) = "" Cells(13, 4) = "" Cells(14, 4) = "" Cells(15, 4) = "" Cells(16, 4) = "" Cells(17, 4) = "" Cells(18, 4) = "" Cells(19, 4) = "" Cells(20, 4) = "" Cells(12, 5) = "" Cells(13, 5) = "" Cells(14, 5) = "" Cells(15, 5) = "" Cells(16, 5) = "" Cells(17, 5) = "" Cells(18, 5) = "" Cells(19, 5) = "" Cells(20, 5) = "" Set CurrentChart = Sheets("Charts").ChartObjects(1).Chart CurrentChart.Parent.Width = 426 CurrentChart.Parent.Height = 252 ' Save chart as GIF Fname = ThisWorkbook.Path & Application.PathSeparator & "temp.gif" CurrentChart.Export Filename:=Fname, FilterName:="GIF" ' Show the chart img1.Picture = LoadPicture(Fname) End Sub 'clear hall line from graph Private Sub CommandButton12_Click() Cells(10, 17) = "" Cells(11, 17) = "" Cells(12, 17) = "" Cells(13, 17) = "" Cells(14, 17) = "" Cells(15, 17) = "" Cells(16, 17) = "" Cells(17, 17) = "" Cells(18, 17) = "" Cells(19, 17) = "" Cells(20, 17) = "" Cells(10, 18) = "" Cells(11, 18) = "" Cells(12, 18) = "" Cells(13, 18) = "" Cells(14, 18) = "" Cells(15, 18) = "" Cells(16, 18) = "" Cells(17, 18) = "" Cells(18, 18) = "" Cells(19, 18) = "" Cells(20, 18) = "" Set CurrentChart = Sheets("Charts").ChartObjects(1).Chart CurrentChart.Parent.Width = 426 CurrentChart.Parent.Height = 252 ' Save chart as GIF Fname = ThisWorkbook.Path & Application.PathSeparator & "temp.gif" CurrentChart.Export Filename:=Fname, FilterName:="GIF" ' Show the chart img1.Picture = LoadPicture(Fname) End Sub ' clear dranchuk & abu-kassem line from graph Private Sub CommandButton13_Click() Cells(10, 19) = "" Cells(11, 19) = "" Cells(12, 19) = "" Cells(13, 19) = "" Cells(14, 19) = "" Cells(15, 19) = "" Cells(16, 19) = "" Cells(17, 19) = "" Cells(18, 19) = "" Cells(19, 19) = "" Cells(20, 19) = "" Cells(10, 20) = "" Cells(11, 20) = "" Cells(12, 20) = "" Cells(13, 20) = "" Cells(14, 20) = "" Cells(15, 20) = "" Cells(16, 20) = "" Cells(17, 20) = "" Cells(18, 20) = "" Cells(19, 20) = "" Cells(20, 20) = "" Set CurrentChart = Sheets("Charts").ChartObjects(1).Chart CurrentChart.Parent.Width = 426 CurrentChart.Parent.Height = 252 ' Save chart as GIF Fname = ThisWorkbook.Path & Application.PathSeparator & "temp.gif" CurrentChart.Export Filename:=Fname, FilterName:="GIF" ' Show the chart img1.Picture = LoadPicture(Fname) End Sub ' clear dranchuk-purvis line from graph Private Sub CommandButton14_Click() Cells(10, 20) = "" Cells(11, 20) = "" Cells(12, 20) = "" Cells(13, 20) = "" Cells(14, 20) = "" Cells(15, 20) = "" Cells(16, 20) = "" Cells(17, 20) = "" Cells(18, 20) = "" Cells(19, 20) = "" Cells(20, 20) = "" Cells(10, 21) = "" Cells(11, 21) = "" Cells(12, 21) = "" Cells(13, 21) = "" Cells(14, 21) = "" Cells(15, 21) = "" Cells(16, 21) = "" Cells(17, 21) = "" Cells(18, 21) = "" Cells(19, 21) = "" Cells(20, 21) = "" Set CurrentChart = Sheets("Charts").ChartObjects(1).Chart CurrentChart.Parent.Width = 426 CurrentChart.Parent.Height = 252 ' Save chart as GIF Fname = ThisWorkbook.Path & Application.PathSeparator & "temp.gif" CurrentChart.Export Filename:=Fname, FilterName:="GIF" ' Show the chart img1.Picture = LoadPicture(Fname) End Sub ' example 1 Private Sub CommandButton16_Click() txt1.Value = 0.85 txt2.Value = 0.04 txt3.Value = 0.03 txt4.Value = 0.03 txt5.Value = 0.02 txt11.Value = 0.02 txt12.Value = 0.01 cmbp.Text = "psi" cmbt.Text = "Fahrenhite" txtp.Value = 3000 txtt.Value = 180 End Sub ' clear all Private Sub CommandButton2_Click() Cells(10, 17) = "" Cells(11, 17) = "" Cells(12, 17) = "" Cells(13, 17) = "" Cells(14, 17) = "" Cells(15, 17) = "" Cells(16, 17) = "" Cells(17, 17) = "" Cells(18, 17) = "" Cells(19, 17) = "" Cells(20, 17) = "" Cells(10, 18) = "" Cells(11, 18) = "" Cells(12, 18) = "" Cells(13, 18) = "" Cells(14, 18) = "" Cells(15, 18) = "" Cells(16, 18) = "" Cells(17, 18) = "" Cells(18, 18) = "" Cells(19, 18) = "" Cells(20, 18) = "" Cells(10, 19) = "" Cells(11, 19) = "" Cells(12, 19) = "" Cells(13, 19) = "" Cells(14, 19) = "" Cells(15, 19) = "" Cells(16, 19) = "" Cells(17, 19) = "" Cells(18, 19) = "" Cells(19, 19) = "" Cells(20, 19) = "" Cells(10, 20) = "" Cells(11, 20) = "" Cells(12, 20) = "" Cells(13, 20) = "" Cells(14, 20) = "" Cells(15, 20) = "" Cells(16, 20) = "" Cells(17, 20) = "" Cells(18, 20) = "" Cells(19, 20) = "" Cells(20, 20) = "" Cells(10, 21) = "" Cells(11, 21) = "" Cells(12, 21) = "" Cells(13, 21) = "" Cells(14, 21) = "" Cells(15, 21) = "" Cells(16, 21) = "" Cells(17, 21) = "" Cells(18, 21) = "" Cells(19, 21) = "" Cells(20, 21) = "" Cells(10, 22) = "" Cells(11, 22) = "" Cells(12, 22) = "" Cells(13, 22) = "" Cells(14, 22) = "" Cells(15, 22) = "" Cells(16, 22) = "" Cells(17, 22) = "" Cells(18, 22) = "" Cells(19, 22) = "" Cells(20, 22) = "" Cells(12, 4) = "" Cells(13, 4) = "" Cells(14, 4) = "" Cells(15, 4) = "" Cells(16, 4) = "" Cells(17, 4) = "" Cells(18, 4) = "" Cells(19, 4) = "" Cells(20, 4) = "" Cells(12, 5) = "" Cells(13, 5) = "" Cells(14, 5) = "" Cells(15, 5) = "" Cells(16, 5) = "" Cells(17, 5) = "" Cells(18, 5) = "" Cells(19, 5) = "" Cells(20, 5) = "" txt1.Value = "" txt2.Value = "" txt3.Value = "" txt4.Value = "" txt5.Value = "" txt6.Value = "" txt7.Value = "" txt8.Value = "" txt9.Value = "" txt10.Value = "" txt11.Value = "" txt12.Value = "" txtp.Value = "" txtt.Value = "" cmb1.Value = "" cmbp.Value = "" cmbt.Value = "" txtan1.Value = "" txtan2.Value = "" txtan3.Value = "" txtan4.Value = "" img1.Picture = Nothing End Sub ' print Private Sub CommandButton3_Click() firstfrm.PrintForm End Sub ' exit Private Sub CommandButton4_Click() ThisWorkbook.Save ThisWorkbook.Close End Sub ' example 2 Private Sub CommandButton5_Click() txt1.Value = 0.75 txt2.Value = 0.07 txt3.Value = 0.05 txt4.Value = 0 txt5.Value = 0.04 txt6.Value = 0 txt7.Value = 0.04 txt8.Value = 0.03 txt9.Value = 0.02 txt10.Value = 0 txt11.Value = 0 txt12.Value = 0 cmbp.Text = "psi" cmbt.Text = "Rankin" txtp.Value = 1000 txtt.Value = 700 End Sub ' example 3 Private Sub CommandButton6_Click() txt1.Value = 0.9712 txt2.Value = 0.0242 txt3.Value = 0.0031 txt4.Value = 0.0005 txt5.Value = 0.0002 txt6.Value = 0 txt7.Value = 0 txt8.Value = 0.0002 txt9.Value = 0.0006 txt10.Value = 0 txt11.Value = 0 txt12.Value = 0 cmbp.Text = "psi" cmbt.Text = "Fahrenhite" txtp.Value = 3810 txtt.Value = 194 End Sub ' example 4 Private Sub CommandButton7_Click() txt1.Value = 0.63 txt2.Value = 0.02 txt3.Value = 0 txt4.Value = 0 txt5.Value = 0 txt6.Value = 0 txt7.Value = 0 txt8.Value = 0 txt9.Value = 0 txt10.Value = 0.2 txt11.Value = 0.1 txt12.Value = 0.05 cmbp.Text = "psi" cmbt.Text = "Fahrenhite" txtp.Value = 1000 txtt.Value = 110 End Sub ' full screen Private Sub UserForm_Initialize() With Application .WindowState = xlMaximized Zoom = Int(.Width / Me.Width * 90) Width = .Width Height = .Height End With End Sub