Thanks for posting on PI Square.
As a preface, I would like to ask what is the particular need to use the steam equations in VBA. Would it be possible to use a PI Dataset or Analysis Tag or Performance Equation Tag to call the function?
Based on our documentation, Pressure must be between 0.088589 to 16000 PSIA and Temperature must be between 32 to 1600 degF. You can implement an if-else statement to check those 2 inputs to see if you are outside of our ranges. If the inputs are within the range, than you can run the steam equation.
1 of 1 people found this helpful
I am using VBA because the report is rather complex, and draws data from multiple sources. It also accepts user parameters that don't cascade well through the report using in-cell functions. A blend is possible, but I try to use the spreadsheet as just the user interface and VBA to power the functionality. Writing and reading values to the spreadsheet as part of the calculation process is messy.
The same run-time error can occur within the boundary values if the passed parameters for temperature and pressure are below the saturation curve. Unfortunately, I don't know if the steam is saturated, superheated, or mixed phase.
I ended up creating a function that encapsulates the StmEng_HPT PI call and use the "On Error Resume Next" VBA method of handling run-time errors. If any error occurs with the PI server call, the encapsulating function clears the error and returns a value of -1 to the main sub. This keeps the scope of the resume to just the specific PI call and benign if another error happens to occur. It also replicates the behavior expected by the OSIsoft documentation without interrupting the main sub.
This seems to work well.