This is the sixth part in a series of VBA tips showing how a user can create and manipulate diagrams, symbols, and definitions from within System Architect's VBA Editor. In the last tip and before, we have created a diagram and placed upon it several symbols. We then modified and experimented with the aesthetics of our symbols, by utilizing the Diagram and Symbol classes' attributes and methods as well as the Symbol Fields.
In this tip we will begin with a new subroutine and create a new SA definition by using the Encyclopedia class' CreateDefinition method.
Let's start a new subroutine in which we will create a definition.
- In the VBA IDE, select Insert, Procedure.
- In the Insert, Procedure dialog, type Main3 as the name of the new procedure. (Keep its Type as Sub and its Scope as Public.)
Like we did when we created a diagram, add the following code to dimension a variable and set it to a System Architect application, and then free its memory.
Dim sa as SA2001.Application Set sa = New SA2001.Application
Set sa = Nothing
Now we will dimension a new variable, myDefinition, and use the Encyclopedia Class' CreateDefinition method to create a new Elementary Business Process definition, which we will call "My Definition".
Dimension the new myDefinition variable by adding the following to Dim sa as SA2001.Application:
Dim sa as SA2001.Application, myDefinition as SA2001.Definition
Create a new Elementary Business Process by typing the following:
Set myDefinition = sa.Encyclopedia.CreateDefinition("My Definition",
As you type in the final comma, you see from the Intellisense pop-up that you need to specify the type of definition for the CreateDefinition's second parameter - SAType as Long.
- To get the internal constant name of the Elementary Business Process' type, you must import the System Architect defns.bas file, which contains a list of every definition's internal name and number, from the File, Import File menu. Double-click on the definitions module in the VBA IDE browser (upper left) to view the defns.bas file. Search the right-hand column for Elementary Business Process. Once you find it, note that the diagram constant and number is DFXELEMBUSPROC = 308.
Finish the Set myDefinition line by typing in the following:
Set myDefinition = sa.Encyclopedia.CreateDefinition("My Definition", DFXELEMBUSPROC)
Quick Tip: You can take advantage of the intellisense features of VBA by pressing ctrl & spacebar and then typing DFX to go to the first definition type n the list of constants.
Saving the definition
The definition is NOT saved in the encyclopedia and will automatically deleted if you do not use the Save method.
Type the following above the Set myDefinition = Nothing line to save My Definition in the encyclopedia:
Your code should look like the following:
After stepping through the code, the Elementary Business Process definition, My Definition, should appear in the System Architect browser.
Keyed definitions exist where the definition name is only unique within the context of any keyed fields. For example, an Entity in an Entity Relation diagram is only unique within a given Model. Therefore, the Model Name keys the Entity or the Entity is keyed by the Model Name.
To set the key properties for a definition, you will need to use the SetProperty method of the Definition class. For example, in the case of the an Attribute of an Entity, you might type:
myDefinition.SetProperty "Model", Chr(34) & "Main Model" & Chr(34) myDefinition.SetProperty "Entity Name", "Customer"
Some definition types require that you must set the keys before you save the definition. These definitions have the term REQUIRED placed within their syntax in the saprops.cfg file.
The next tip will be the last in this series of VBA tips. We will explore the MetaItem and MetaProperties classes and retrieve the metaproperties of the definition we created in this tip.