VBA display code

Display code is Visual Basic code that is associated with a graphic display. It is created with Visual Basic for Applications and is saved as part of a display. Display code runs when the display, or objects on the display, raise events. Events are only raised when a display is tested in the Graphics editor or run in a FactoryTalk View SE Client. Code that runs in response to an event is called an event handler.
By default, when an object is added to a Graphic display, it is not exposed as a property of the display and it does not appear in the drop-down list in the code window in VBA because the object's
ExposeToVBA
property is set to
Not Exposed
. This property is provided to improve the performance of loading, editing, and saving displays containing large numbers of objects. The more objects that are exposed as VBA controls, the longer it takes to load a display.
When an object is exposed in VBA, it is easy to read from and write to its properties. You can access the object by typing its name into the code window for the display (the
ThisDisplay
class module). VBA also exposes an object named
Me
that represents the display. When you type
Me.
in the code window for the
ThisDisplay
class, all the properties of the display and the names of the exposed objects are displayed.
To write code for the events of the
Application
object, an application object needs to be dimensioned using the
WithEvents
keyword and then set in a display event (that is,
Display_AnimationStart
).
The following objects can raise events:
  • Application
  • Display
  • Group
  • Button
  • NumericDisplay
  • NumericInput
  • StringDisplay
  • StringInput
  • Recipe
  • Tag
  • TagGroup
  • TagLabel
  • Text
  • Trend
Remarks
  • When a Group object is copied or duplicated, any event handlers for the group are not copied.
  • To stop a Group object from raising events to VBA, select it and then Ungroup it. When you regroup the object, it will no longer fire events in VBA.
  • If a Group object that is exposed to VBA contains objects that generate mouse events, the events for the objects within the Group object will not fire. For example, if a button belongs to a Group object that has its events exposed to VBA, the mouse events for the button will no longer fire.
  • If you copy an object that has VBA code associated with it, the comments might not be copied. The reason for this is that when you add comments to code, it is usually placed above the function. These comments are not copied.
    If you want your comments to be copied with the code, make sure you place them within the function body.
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.
Normal