Working with Models, Modules, and Files in ADE

Revision as of 23:08, 26 May 2015 by Karenlee (talk | contribs)

Models and Modules

Note: In VBScript, VBA, and pre-dot-NET versions of Visual Basic, the Set keyword was necessary when assigning an object to a variable. In VB.NET, the Set keyword is no longer necessary. The Set keyword is not used in the examples below.

  • To create a new model:
If ADE.CreateModel("NewModelName") Then
’Model successfully created
End If

The CreateModel method only requires one parameter, a string containing a model name.

  • To open an existing Analytica model:
Dim ModName as String
ModName = ADE.OpenModel("C:\ ... \Anamodel.ana")
If ModName="" then
’ Handle Error condition here
End if

If a model has already been opened, that model is closed automatically before the new model is created. If the specified filename is not legal, OpenModel returns an empty string. In that case, use the ErrorCode property of CAEngine to determine the cause of the error. Be aware that an ErrorCode=2 warning is often returned even though the load is successful. For full details as to what has caused an error or warning, use the OutputBuffer property of the CAEngine. You must use the backward slash (\) for the path delimiter when using ADE. It does not support the forward slash (/).

  • To add a module from a file to the currently open model:
Dim Merge as Boolean = True
Dim ModName as String
ModName = ADE.AddModule ("C:\...\MyLibrary.ana", Merge)
if ModName="" Then
’ Handle error conditions here
End if

The FileSpec parameter should contain the path and filename of the module to be included. The Merge parameter is a Boolean variable that determines whether preexisting objects with identical names are overwritten. If Merge=True, then conflicting variables are overwritten. If Merge=False and there are conflicting variables, then the call to AddModule fails.

  • To read a script file:
If ADE.ReadScript("C:\..\MyScript.ana") Then
’ Script successfully read
End

If A script file can contain a list of typescript commands. Upon loading the file, the engine executes the commands contained in the file. Errors encountered while running the script file are described in the ErrorText property.

  • To save a module (i.e., a subset of the current model) in a separate file:
If ADE.SaveModuleFile ("MyLibrary", "C:\...\MyLibrary.ana") Then
’ Save succeeded
End

If The first parameter is the module identifier, the second is the file name.

  • To save the current model in a file:
If ADE.SaveModel("C:\...\MyNewModel.ana") Then
’ Save succeeded
End If
  • To close the current model without saving:
If ADE.CloseModel() Then … ’ Close succeeded

The CloseModel method takes no parameters.

ADE Objects

Retrieving Computed Results

Retrieving Multi-Dimensional Results

Creating Tables and Setting Values in Tables

Adjusting How Values are Returned

Terminating an In-progress Computation

Instantiating CAEnging using CALicense

Using the Analytica Graphing Engine

Comments


You are not allowed to post comments.