Table Of Contents

Executing Code Based on an Event

Version:
Last Modified: January 12, 2018

To execute code based on an event, you must configure the Event Structure to handle events.

Before you configure events for the Event Structure to handle, review the Recommendations for Event-Driven Programming. Complete the following steps to configure an Event Structure case to handle events.
  1. (Optional) If you want to configure the Event Structure to handle an external I/O event or a programmatically generated event, you first must dynamically register that event.
    1. Select the Event Structure. On the Item tab, click Use dynamic events to enable the Dynamic Event Terminals.
    2. Place a Register for Events node on the diagram and wire the output to the input of the Dynamic Event Terminal.
    3. Create diagram code for your event source and wire it to the inputs of Register for Events.
  2. Select the Event Structure. On the Item tab, click Select handled events to display the Select Handled Events dialog box.
  3. In the Select Handled Events dialog box, select the events for which you want to respond. The Select Handled Events dialog box displays events available for the panel, panel controls, and any events for which you dynamically register.
  4. Click OK to save the configuration and close the dialog box. The event case you configure appears as a selection option in the event selector label at the top of the Event Structure and the Event Data Node displays the data common to all events handled in that case.
  5. Create the code you want the Event Structure to execute when the event occurs. Place this code inside the Event Structure.
  6. (Optional) Use a Timeout event to configure an Event Structure to wait a specified amount of time for an event to occur. If no event occurs before the specified amount of time passes, the Event Structure stops handling events.
  7. Add additional event cases as required by your application.
    1. Select the Event Structure. On the Item tab, click + to add additional event cases.
    2. Repeat steps 1 through 6 for each event case you want to configure.

Recently Viewed Topics