2 Replies Latest reply on Dec 21, 2017 4:01 PM by nmosher

    PI Steam Tables and Excel VBA


      I'm successfully using the StmEng_HPT function in VBA, but I get a run-time error when the inputs are out of range.  The documentation says that the PI Server will return -1 in this case, but I'm getting a run-time error for "Argument value out of range".  How do I properly handle this error in VBA?  I would like to test whether or not the values are out of range, and do something different if they are without stopping the rest of my code from executing.



      - Nick

        • Re: PI Steam Tables and Excel VBA

          Hi Nicholas,


          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.



          • Re: PI Steam Tables and Excel VBA



            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.

            1 of 1 people found this helpful