While the example scripts provided in this guide are written in VBScript, it is possible to use also other languages with QPR API. VBScript is utilized in the example for the sake of simplicity and its applicability for writing automation scripts. However, if you require for instance better user interface controls with your application utilizing the QPR API, you can use for example Microsoft Visual Studio with VB.NET or C# to create your application, but there are some important areas to consider:
•The language needs to be able to create COM objects
•Due to the nature of the QPR API functions, a considerable amount of typecasting is required.
•It needs to kept in mind that even if you build a .NET application with full Windows Forms user interface, it is still dependent on having QPR Modeling/QPR Metrics clients installed on the same machine in order for the application to actually work.
•As most of the arrays returned by QPR API are returned as variant data type, the language needs to support the variant data type.
Typecasting is needed especially with return values since the return value is always an integer value telling whether the function call was successful. The actual return values are stored in one of the parameters of the QPR API call and they are always objects even though their intended use requires a more specific type. A recommended approach is to write a wrapper class for the SCApplication/PGApplication and SCModel/PGModel classes and handle the typecasting in the wrapper classes.
Example QPR API function call without a wrapper class:
retval = _scMod.GetFormula(id, (object)series, out outObj);
formula = (string)outObj;
Example QPR API function call with a wrapper class:
string formula = _model.GetFormula(id,”ACT”);
The wrapper class in this case contains code such as
public string getFormula(int elementId, string series)
iResult = (int)this._scModel.GetFormula(elementId, (object)series, out outObj);
if (iResult != 0) throw new Exception((string)this._scApp.GetErrorMessage(iResult));
Tips and Recommendations
Instead of using CreateObject to create the SCApplication/PGApplication object, it is recommended to add the client libraries as COM references to the Visual Studio project. With a COM reference you can instantiate the class in the following way:
SCApplication _scApp = new SCApplication();
With this approach you gain also IntelliSense support for accessing QPR API functions easily from Visual Studio. You can add the reference in the following way:
1.Right-click on your application in the Solution Explorer (usually located right below the solution itself)
2.Select Add Reference
3.Switch to the COM tab
4.Select SCClient (QPR Metrics) library or proguide (QPR Modeling Client) Library depending on which one you need (note that the libraries are available only if the clients are properly installed on the system)