This is the third part in a series of VBA tips that show how a user can create and modify his own System Architect diagrams, symbols, and definitions. As stated previously, System Architect's support for Microsoft's Visual Basic for Applications can be very beneficial in modifying and extending SA functionality. So far, we have created a diagram and in the last tip we added three symbols to it.
In this tip we will show how you can use a line, link, or association symbol to connect other symbol, by utilizing the ConnectTo and ConnectFrom methods of the Symbol class. The following is the code we had written previously:
Making the line symbol connect to other symbols
In our Process Chart, we created two elementary business processes and one mandatory sequence link. Now we must connect the two EBP's to show which route an object will follow in the Process Chart. We will use the symbol class' ConnectTo and ConnectFrom methods.
Let's try connecting the line symbol to the two EBP symbols.
-
In the Immediate window, type:
SaLineSym.ConnectTo(
Notice that the ConnectTo method needs a Line as Symbol as a parameter. Since we are already working with the line, this is obviously not the way to go. Let's instead start with one of the symbols, and specify that the line get connect from/to it.
-
Delete that line, and type in the following:
SaSymbol1.ConnectFrom(
Again, it is asking for Line as Symbol for its parameter. Add the following to the line and hit Enter:
SaSymbol1.ConnectFrom(saLineSym)
When you hit Enter, you should get an error message that says Run-time error.. Object doesn't support this property or method. When you type a parenthesis around the method's parameter, the method will provide a return type; you would normally have an '=' at the front of the line, specifying a variable that the return is put into. For our example, we don't need to use the method this way; we'll simply delete the open/close parenthesis.
Adjust the line in the Immediate window to look as follows:
SaSymbol1.ConnectTo saLineSym
and hit Enter.
Take a look at the diagram, and notice that the line symbol has been connected to the first EBP symbol.
Let's use the ConnectFrom method to connect the line to the other symbol.
-
In the Immediate window, type the following:
SaSymbol2.ConnectFrom saLineSym
and hit Enter.
The two EBP symbols should now be connected to each other by the line.
- Select the two lines of code you have written into the Immediate window, cut them (CTRL-X) and paste them (CTRL-V) into your code, so that your code looks as follows:
Next tip
We have just connected two symbols with a line symbol in VBA, an important step in creating a detailed and useful diagram. In the next tip, we will explore how you can position the symbols anywhere on the diagram.
-
Click on File, Save Tutorial and exit the VBA Editor.
Important Note: DO NOT save My Diagram when closing System Architect! An SAIMF error will appear next time you step through the code, stating that "My Diagram already exists".