There's a different parent object in the script interpreter within ER/Studio as compared to the parent object named using an externally created executable, such as a VB program from Microsoft's Visual Studio. In the latter case, you're using ER/Studio's COM automation interface that supports BASIC. Invoke The Programmatic Id (PROGID) for ER/Studio: 'ERStudio.Application'.
Working examples of this type exist in MSVB6, .Net VB and C# and are in your ER/Studio application directory under "..\Readme\TableList.zip."
Macros which run inside ER/Studio's SAX BASIC shell will use the pre-initialized 'DiagramManager' object. There are numerous examples of this in ER/Studio's Macro Tab and in the Code Samples section of this online help file.
To summarize: Outside ER/Studio you begin with an instance of ERStudio.Application. Inside you begin with DiagramManager, and an instance is already running.
To check for errors after method calls, use the DiagramManager.GetLastErrorCode() or DiagramManager.GetLastErrorString().
In the list of Members of an object, the comments for METHOD, PROPERTY, PARAMETERS, and DESCRIPTION are written by the automation interface engineers. These comments include instructions or valid parameter lists. Where PARAMETERS are listed, they are usually more tightly-scoped than the universal BASIC type "Variant." Use the specific datatype as listed in PARAMETERS in your code. In the example above, you might write in your code:
Dim MyDiagram As Diagram
Dim MyFilePath As String
'**************
'NOT as Variant
'**************
MyFilePath = "C:\Model\ElleModel.dm1"
Set MyDiagram = DiagramManager.OpenFile(MyFilePath )
DEFINITION: Function OpenFile(FullFilePath) As Diagram
This is the actual source code definition. In the example, Function
means a function (equivalently here, "method") is being defined.
"FullFilePath"
is the only argument that OpenFile
takes.
"As Diagram"
means that OpenFile
returns a custom datatype "Diagram"
. Other methods and properties may return typical data types such as Integer
or String.
PARAMETERS lists any arguments the method/property takes and of what Type. In some places you may notice a difference between the datatype in the comments and the Type listed in the Parameters table. Such is the case above, where FullFilePath is listed as Type Variant in the table but as String in the comments.
The table lists the actual automation interface source-code definition, whereas the comments list the intended target type in ER/Studio.
Variant is a BASIC super-type that contains all but custom datatypes. You can generally declare any variable to be Variant and restrict it further when you use it, say, as a Boolean. The automation interface is defined in this way, but you should use the intended specific datatype in your code.
In other words, don't declare a Variant
-type variable if you can use the specific data type, such as String
in the example above.
Why am I using "DiagramManager" and not "Application" in the example above?
Outside ER/Studio (COM programming) you begin with an instance of ER/Studio.Application. Inside the ER/Studio Macro Editor you begin with DiagramManager, and an instance is already running. It's the only such difference in the entire object set. If you write programs only within ER/Studio, it will appear as above and you don't have to bother with it further. Otherwise, see the External COM Programming vs ER/Studios Macro Window notes above.
A property can be defined as Get/Let, meaning you can read the property (Get) or change it (Let). However, many properties such as numeric IDs, are set by ER/Studio and are in fact read-only; they are defined with Get
but not Let
permissions. For example, most of the numeric IDs are Get
only.
In general, if you can edit a property using ER/Studio's GUI design controls, and there exists an automation object for it, it will exist as Get/Let. If you can't edit it in ER/Studio, it's read-only (Get
-only).
The code EXAMPLES in this reference do not always use "Set"
. In the SAX BASIC Editor within ER/Studio, you must use the function "Set"
on the first instance of the object in a script (or block of code within object scope). You must use it again if the object reference changes.
Example:
Set MyDiagram = DiagramManager.ActiveDiagram
'some code that closes the active diagram and opens another diagram
Set MyDiagram = DiagramManager.ActiveDiagram
SAX BASIC will not allow you to declare and initialize any variable in one statement.
Example:
Dim MyData As Integer = 30 'No way
Dim MyData As Integer
MyData = 30 'OK
Where a platform is specified by integer, use the following: