Using WaterSteamPro in WSH (Windows Scripting Host)

Windows Scripting Host is the technique of program creation in Windows using the script languages. This technique has replaced bat files of MS-DOS. Standard Windows 98 delivery package presents two script languages: JScript (analog of JavaScript) and VBScript (Visual Basic Scripting Edition). A program for WSH represents a text file with a program written in a language supported by WSH.

In what follows there are illustrated two files designed for WSH and written in JScript and in VBScript. The files enable calculation of specific volume, specific enthalpy and specific entropy in a point defined by preset values of pressure and temperature, which are program arguments and are defined at a program-file call. In the absence of arguments the program calculates default parameters. Otherwise, the first argument - is pressure (Pa), and the second one - temperature (K).

The file "WaterSteamPro.js", programming language - is JScript:

var wsp = WScript.CreateObject("WSP.WSPCalculator");
var wshshell = WScript.CreateObject("WScript.Shell")
if (! wsp)
{
   wshshell.Popup('Error with creating ActiveX object!',0,'',0)
   WScript.Quit();
}else
{
   var arg = WScript.Arguments;
   var p = 1000000;
   var t = 400;
   if (arg.length > 1)
   {
      p = arg.Item(0);
      t = arg.Item(1);
   }else
   {
      wshshell.Popup('Arguments absent. Loaded default values!',0,'',0);
   };
   var v = wsp.wspVPT(p, t);
   var s = wsp.wspSPT(p, t);
   var h = wsp.wspHPT(p, t);
   wshshell.Popup('P='+p+'Pa;T='+t+'K;V='+v+'m3/kg;S='+s+'J/kg*K;H='+h+'J/kg',0,'',0);
}

The given example applies the technique described above in the section "Operation of WaterSteamPro in Microsoft Excel" with reference to the function "CreateObject", that is why it is not thoroughly described here and only the most common features are stated here

First lines provide creation of two objects: the first object allows access to functions for calculation of properties of water and water steam, and the second one - serves to display messages. Then the program verifies whether a "WSP.WSPCalculator" object was created and, if not, displays a warning message and terminates operation. If an application object was created successfully the following variables are defined: the variable "arg" keeping set of arguments (which are specified in the command line) required at a file call, and two variables keeping default design values of parameters (the design value of pressure "p" - is 1000000, and the design value of temperature "t" - is 400). After that the program checks number of arguments and if their quantity exceeds unit (two or more), the variables "p" and "t" take respectively the value of the first and the second argument (argument numbers are - zero and unit). Otherwise, the message on the absence of arguments is displayed and the program operates with default values. The next stage comprises reference to methods of created "wsp" object (of "WSP.WSPCalculator" type) which return values of specific volume, entropy and enthalpy. A message presenting obtained calculation results is displayed on completion of program operation.

Let us investigate the file "WaterSteamPro.vbs", the programming language - is VBScript. The program algorithm is identical to the one described above, and all the differences are related to a specific character of the programming language:

Set wsp = WScript.CreateObject("WSP.WSPCalculator")
Set wshshell = WScript.CreateObject("WScript.Shell")
if Not IsObject(wsp) Then
   wshshell.Popup "Error with creating ActiveX object!",0,"",0
   WScript.Quit
Else
   Set arg = WScript.Arguments
   Dim p
   p = 1000000
   Dim t
   t = 400
   if arg.length > 1 Then
      p = arg.Item(0)
      t = arg.Item(1)
   else
      wshshell.Popup "Arguments absent. Loaded default values!",0,"",0
   End if
   dim v
   v = wsp.wspVPT(p, t)
   dim s
   s = wsp.wspSPT(p, t)
   dim h
   h = wsp.wspHPT(p, t)
   wshshell.Popup "P=" & p & ";T=" & t & ";V=" & v & ";S=" & s & ";H=" & h & "",0,"",0
end if