Usage of the ActiveX-objects of "WSP.WSPCalculator" in Microsoft Excel

The "WSP_EXCEL.XLS" file presents an example of operation of the "WaterSteamPro" package in Microsoft Excel. The Microsoft Excel version therewith should not be lower than 8.0 (Microsoft Excel 97).

The example under consideration uses ActiveX-objects of "WSP.WSPCalculator" in order to gain an access to functions of the "WaterSteamPro" package. For this purpose, a new module in the Visual Basic for Applications (VBA) editor is generated, containing codes of created stub-functions. To jump to the Visual Basic editor you may press the key combination Alt-F11, or select the item "Visual Basic Editor" from the "Tools/Macro" menu.

Furthermore a "WSP.WSPCalculator" object is accessible in two ways. The first one - is to create an application object by means of the function "CreateObject (class, [servername])", which creates an ActiveX-object with a name "class" and a server with a name "servername". Function code in this case, for example, at calculation of saturation depending on temperature, is presented below:

Function PST(t as double) as double
Dim wsp as object
Set wsp = CreateObject("WSP.WSPCalculator")
PST = wsp.wspPST(t)
End function

Let's examine this example. We define the function "PST" ("double" type), which returns saturation pressure depending on temperature "t" ("double" type). Then we define the variable named "wsp" of "object" type. And in the next line the "wsp" variable takes a result returned by the function "CreateObject" obtained with a parameter "WSP.WSPCalculator". Thereafter a value returned by the "wspPST" function of created "WSP.WSPCalculator" application object, named "wsp", is used as the result of the "PST" function.

The disadvantage of this technique is that every call of the function results in creation of a new "WSP.WSPCalculator" application object.

Another way to gain an access to a "WSP.WSPCalculator" object - is to connect all ActiveX objects from the OKAWSP5.DLL library to an Excel document. To do this select the item "References" from the "Tools" menu. Tick the "WaterSteamPro" element in the displayed list (see Fig. 4) and push OK.

Fig. 4. Insertion of reference to the library

The given technique allows all ActiveX objects from a connected library to become accessible. The following code allowing access to "WaterSteamPro" functions is enabled now (we define an alternative function for calculation of saturation depending on temperature):

Public wsp2 As New Wsp.WSPCalculator
Function PST2(t as double) as double
PST2 = wsp2.wspPST(t)
End function

Let's examine this example. The variable "wsp2" of "Wsp.WSPCalculator" type is defined in the module (not in the function). And stub-functions refer to methods of this variable.

The second method has the advantage of using the Microsoft IntelliSence technology for creation of functions allowing display of all accessible functions. This is also possible by using Object Browser (F2 key). The second advantage of this method - lies in speed of function operation - an ActiveX-object is created only once, rather than at each function call.

In a similar manner, the "WaterSteamPro" package can be used in any program environment "acquainted with" Visual Basic. In principle, it was possible to organize an analogous access to functions in the program "WaterSteamPro Calculator" (the Microsoft Visual Basic version), but a direct DLL call is executed faster than a call through ActiveX objects.