Function SimpPress(P As Double, InputP As String, OutputP As String)
' This first converts pressure to MPa and then back to whatever
' It currently accepts as types: MPa, Pa, psia, psig, in_H2O
If UCase(InputP) = UCase(OutputP) Then
SimpPress = P: Exit Function
Else
Dim Mult1 As Double, Const1 As Double, Mult2 As Double, Const2 As Double
Mult1 = 1: Const1 = 0: Mult2 = 1: Const2 = 0
Select Case UCase(InputP)
Case "MPA"
Case "PA": Mult1 = 0.000001
Case "PSIA": Mult1 = 0.00689475729 '1 pound per square inch = 0.00689475729 megapascals
Case "PSIG": Mult1 = 0.00689475729: Const1 = 0.101325
Case "IN_H2O": Mult1 = 0.00024908891 '1 inch of water = 0.00024908891 megapascals
Case Else: SimpPress = InputP & "?": Exit Function
End Select
Select Case UCase(OutputP)
Case "MPA"
Case "PA": Mult2 = 1000000
Case "PSIA": Mult2 = 145.037738 '1 megapascal = 145.037738 pounds per square inch
Case "PSIG": Mult2 = 145.037738: Const2 = -14.6959488
Case "IN_H2O": Mult2 = 4014.63076 '1 megapascal = 4014.63076 inches of water (1/0.00024908891)
Case Else: SimpPress = OutputP & "?": Exit Function
End Select
SimpPress = (P * Mult1 + Const1) * Mult2 + Const2
End If
End Function