VBA allows you to add an object library or type library reference to your project, which makes another application's objects available in your code. These additions to your VBA project are called references. You can view, add, and delete references by selecting the References command from the Tools menu in the Visual Basic Editor (VBE).
Whenever you add a control into a picture, the control's type library is referenced by the picture within VBA. When you delete a control from a picture, the reference to the control is automatically removed to increase performance. However, you should never manually remove the references to "Project_FactoryGlobals" or "Project_User".
Whenever you reference objects, controls, or mechanisms in VBA, follow the guidelines in the following sections. To learn more about references in VBA, refer to the VBA Help file.
Deleting Objects Referenced by Name in a Script
Any object that is referenced by name in a script cannot be deleted. For example, in the following sample script the code in Rect2_Click will execute, but the pen will not be deleted:
Rect1_Click()
Pen1.Source = "Fix32.ThisNode.AI_30.F_CV"
End Sub
Rect2_Click()
Chart1.DeletePen 1
End Sub
If you wanted to access the object in this example without referencing it by name, you could use the following code in Rect1_Click ():
Rect1_Click()
Dim o as object
set o = Chart1.Pens.Item(1)
o.Source = "Fix32.ThisNode.AI_30.F_CV"
End Sub
Using Deleted Object Types in Scripts
When an object (2Dshape, FixDynamics object, ActiveX control) is deleted from a picture and no object of that type are left in the picture, the reference to that object's type library in the VBA project is removed. To continue to use this object's type in scripts, you must manually add a reference to the type library in the VBE by selecting References from the Tools menu and selecting the type library.
Dragging and Dropping Dynamo Objects or Toolbar Buttons
You should be aware of the following behavior when dragging and dropping a Dynamo object into a picture, cutting and pasting a Dynamo object, or dragging and dropping a toolbar button from a category into a toolbar:
- VBA copies all forms, scripts, events, and sub-forms associated with the toolbar button or Dynamo object.
- VBA does not copy any VBA modules or class modules associated with the toolbar button or Dynamo object. Code that you put in these modules will not run if you drag the Dynamo object or the toolbar button to another picture or toolbar.
- VBA does not copy references to other objects such as controls or DLLs that you create for toolbar buttons or Dynamo objects. For example, if you include a third-party OCX as a control on a form for a toolbar button, VBA does not copy the reference when you drag the toolbar button to a toolbar. The script will not run until you open the Visual Basic Editor and create a reference to the OCX for the toolbar project.