15_IntroToScripting
15_IntroToScripting
Chapter 15
Section Objectives
This section begins a topic that will be used throughout the remainder of the course. That topic
is scripting. iFIX uses Visual Basic for Applications (VBA) as its scripting language. Scripting
can be used in many places throughout iFIX. This section includes:
Many of the terms introduced in this section will be referenced later in the course.
System System
Configuration Configuration
I/O Driver
Configuration
Graphics
Development
Process Database
Development
Alarm Alarm
Configuration Monitoring
Security Security
Configuration Configuration
A. Terminology:
• VB - Visual Basic
- usually refers to Microsoft® Visual Basic® 5.0 or 6.0
- this is external to iFIX and VBA
• VBA - Microsoft® Visual Basic® for Applications
- an object-oriented and event-driven development environment that
supports Microsoft forms and ActiveX
- usually referred to as it is integrated into iFIX
- used throughout Microsoft products for customization
◊ adding a toolbar in Excel
◊ creating a form in Access
• VBE - Visual Basic Editor
- part of VBA
- accessible from the Intellution WorkSpace
B. Overview
• VBA code is saved in either:
- a picture (GRF file)
- a schedule (EVS file)
- a global object (User.fxg)
• Scripting in iFIX allows access to:
- standard VBA components
- all exposed iFIX objects and their properties, methods, and events
◊ see Figure 15-3 for definitions
• The properties, methods, and events available for an individual object are based
on the object class
- Example:
◊ Rectangle objects do not have the same font properties as text
objects
• Objects respond to events based on scripts that are written for each event
- scripts can be written for one event, some events, or all events, depending
on what needs to be accomplished
VBA Terminology
Objects Comprised of data and procedures that are treated as a unit
Each object has its own properties, methods, and events that can
be used to write scripts
Examples: Rectangle, Timer, Schedule Event
Properties Characteristics of an object
Examples: color, size, location in the picture
Methods Subroutines that effect the behavior of object
Examples: such as scale or refresh
Events Actions that the object recognizes, such as when a user clicks the
mouse on the object or changes its size
If a script is associated with an event, the script executes when
the event triggers or occurs
Events can occur as a result of user action, program code, or other
occurrences in iFIX
Examples: mouse click, value reaches a threshold
D. Task Wizard
• Tool used to access all experts
• Experts are separated into categories:
- Animation
- Command
- Database
- Data Entry
- Picture
- Report
Data Entry
Open Picture
Close Picture
Replace Picture
Open Digital Tag
Close Digital Tag
Toggle Digital Tag
Acknowledge Alarm
A. Example
• VBE – Visual Basic Editor
• Figure 15-5 shows an example of a simple script using the VBE
- Line 1 - creates the script (or subroutine) called Rect5_Click()
◊ this is a script connected to an object called Rect5
◊ the script is run when the Rect5 object is clicked
- Line 2 - runs the command CloseDigitalPoint
◊ this sends a value of 1 to the data source listed
- Line 3 - tells the script to stop executing
• See pages 15-12 and 15-13 for additional sample scripts
OpenPicture "Picture2"
End Sub
End Sub
AcknowledgeAllAlarms "Picture2"
End Sub
Rect2.RotationAngle = Rect2.RotationAngle + 20
End Sub
iValue = ReadValue("fix32.node8.AI1.f_cv")
End Sub