Ifix 354
Ifix 354
Ifix 354
ZZZML\LWHFKFRP
Intellut on
Educational Services
*()DQXF
ZZZML\LWHFKFRP
*()DQXF
ZZZML\LWHFKFRP
Intellut on
Name: _________________________________
Date: ____________________________
Title: __________________________________
Course:
Instructor: ________________________
354 v2.1-7.99
E-mail: _______________________________________________________________________
Company Name and Address: _____________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
Hotel where you are staying: ______________________________________________________
1. Have you used any Intellution, Inc. products? Yes No
If so, please note how long you have been working with the product(s):
2. Have you ever attended an Intellution training class before today? Yes No
FIX Fundamentals (FIX 104)
iFIX for New Users (154A)
Advanced FIX (FIX 204)
iFIX for FIX Users (154B)
iBatch Basics (114)
Advanced iFIX (254)
Other
SI: ______
Rep: ______
OEM ______
A&E: ______
Other (explain): _________________
*()DQXF
ZZZML\LWHFKFRP
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Proprietary Notice
The manual and software contain confidential information which represents trade secrets of
Intellution, Inc. and/or its suppliers, and may not be copied or disclosed except as provided in the
license with Intellution, Inc. The information in this manual is subject to change without notice
and should not be construed as a commitment by Intellution, Inc. Intellution, Inc. assumes no
responsibility for any errors that may be in this document.
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
1.
1.1.
VBA Scripts........................................................................
1.1.1. Understanding Objects ..................................................
1.1.2. Object Properties...........................................................
1.1.3. Object Methods .............................................................
1.1.4. Object Events ................................................................
1-4
1-6
1-8
1-10
1-11
1.2.
Container Objects................................................................ 1-12
1.2.1. iFIX Container .............................................................. 1-14
1.2.2. VBA and iFIX Container............................................... 1-16
1.3.
1.4.
1.5.
1.6.
1.7.
1.8.
2.
Review................................................................................ 2-3
2.2.
Visual Basic Editor .............................................................
2.2.1. Project Explorer ............................................................
2.2.2. Property Window ..........................................................
2.2.3. Immediate Window .......................................................
2.2.4. Code Window ...............................................................
2-4
2-6
2-8
2-10
2-12
2.3.
2.4.
2.5.
2.6.
ii
*()DQXF
ZZZML\LWHFKFRP
Student Guide
3.
3.1.
4.
3-4
3-6
3-7
3-8
3-10
3-12
3-16
3-17
3-18
3.4.
3.5.
Constants.............................................................................. 3-24
3.6.
3.7.
3.8.
4.1.
4.2. Procedures............................................................................
4.2.1. Understanding Events....................................................
4.2.2. Understanding Scope.....................................................
4.2.3. Procedure Arguments ....................................................
4.2.4. Expressions ...................................................................
4-6
4-10
4-12
4-14
4-18
4.5.
4.6.
4.7.
4.8.
4.9.
iii
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
5.
5.1.
5.2.
5.3.
5.4.
5.6.
5.7.
5.8.
5.9.
6.
5-10
5-12
5-14
5-16
5-18
5-20
5-22
5-23
6.4.
6.5.
6.6.
6.7.
iv
*()DQXF
ZZZML\LWHFKFRP
Student Guide
7.
7.1.
Decision Statements............................................................
7.1.1. If Then Else...................................................................
7.1.2. If Then ElseIf ................................................................
7.1.3. Select Case....................................................................
7.1.4. GoTo.............................................................................
7-3
7-4
7-8
7-10
7-12
7.2.
Looping .............................................................................. 7-13
7.2.1. Do Loops ...................................................................... 7-14
7.2.2. For Next Loop............................................................... 7-16
7.3.
7.4.
7.5.
7.6.
8.
8.1.
Grouped Objects .................................................................
8.1.1. ContainedObjects Property............................................
8.1.2. ContainedSelections Property........................................
8.1.3. Grouped Object Properties ............................................
8.1.4. Group Events ................................................................
8-3
8-4
8-6
8-8
8-10
8.2.
Collections..........................................................................
8.2.1. Pre-Defined Collections ................................................
8.2.2. User Defined Collections...............................................
8.2.3. For Each Next Loop ......................................................
8-11
8-12
8-14
8-19
8.3.
8.4.
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
9.
9.1.
9.2.
9.3.
9.4.
9.5.
9.6.
10.2.
10.3.
10.5.
10.6.
10.7.
10.8.
11.2.
vi
*()DQXF
ZZZML\LWHFKFRP
Student Guide
12.2.
12.3.
12.6.
12.7.
12.8.
13.1.
13.2.
13.3.
13.4.
13.5.
13.6.
OLE.................................................................................... 13-16
13.7.
13.8.
vii
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Appendixes
B.1.
B.2.
Reading and Writing Data................................................... B-6
B.2.1.
Put Statement ............................................................. B-7
B.2.2.
Get Statement............................................................. B-8
B.2.3.
Input Statement .......................................................... B-9
B.2.4.
Input # Statement ....................................................... B-10
B.2.5.
Write # Statement....................................................... B-11
B.2.6.
Print # Statement ........................................................ B-12
C.2.
viii
*()DQXF
ZZZML\LWHFKFRP
Student Guide
ix
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Section 1
Overview
Introduction to VBA
iFIX and VBA
Container Objects
VBA Code and VBA Help
Automation Interface Help
Section 5
Debugging
Understanding Errors
Debugging Tools
Hints and Tips
Section 6
Introduction to Forms
Creating Forms
Form Controls
Launching Forms
Form Events
Section 2
VBA Environment
Visual Basic Editor
Message Box and Input Box
Section 3
Variables
Data Types
User Defined Data Types
Arrays
Constants
Section 7
Controlling VBA Code
Decision Statements
If Then Else
Case Statement
Loops
For Next Loop
Do Loops
Section 4
Procedures and Functions
Procedures
Class Modules
Expressions
Functions
Object Browser
Section 8
Collections and Groups
Grouped Objects
Group Events
User Defined Collections
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Section 9
Embedded Objects
WorkSpace Variable Object
Timer Object
Event Object
Scheduler
Section 12
Automation
Using Automation
Adding References
Automation Examples
Section 13
ActiveX, Linking, and Embedding
ActiveX
iFIX ActiveX Controls
VBA and ActiveX Controls
Installing ActiveX Controls
OLE
Section 10
iFIX Automation
Accessing the Process Database
iFIX Subroutines
Database Functions
Section 11
Error Handling
Using Error Handlers
Error Handle Examples
VBA Error Codes
Section 14
Accessing a Relational Database
Data Access Objects (DAO)
ActiveX Data Objects (ADO)
xi
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Introduction __________________________________________________
Course Description
This course is designed for those who wish to acquire a basic knowledge of Visual Basic for
Applications (VBA) within the iFIX container. This knowledge will allow the student to
generate VBA based solutions for their special system requirements. The student should be
familiar with the iFIX workspace and its features. The course begins with an introduction to
VBA and why VBA is so important in todays applications. Lectures, coding example, and
labs are included in this course on the important aspects of VBA, as well as reference to
Visual Basic syntax. This course will demonstrate to the student how to enhance runtime
operation to solve special problems. Additionally, the material will present information on
adding custom design tools (like ActiveX objects) and adding online maintenance tools such
as operation manuals, part descriptions, and P&ID views.
Audience
This course is principally designed for system integrators, instrumentation engineers and
process engineers who want to use the power of VBA to create unique solutions for their
applications in the process control industry.
Required Prerequisites
Suggested Prerequisites
Course Duration
Four (4) days.
xii
*()DQXF
ZZZML\LWHFKFRP
Student Guide
1. Overview __________________________________________________
Chapter 1
Overview
1-1
*()DQXF
1.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Overview _________________________________________________
Section Objectives
This section provides an introduction to the VBA and the iFIX object Hierarchy. The student
will run through a VBA sample application and discuss how objects are used within VBA. This
includes the following:
Container Objects
VBA Help
In addition, this section will also introduce important terminology used throughout the course.
1-2
*()DQXF
1.
ZZZML\LWHFKFRP
Student Guide
Overview _________________________________________________
A. What is VBA?
B. Terminology:
VB Visual Basic
-
Visual Basic uses Visual Basic for Applications as its central code engine
VBA creates script code and does not create executables or .DLLs
1-3
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Typical users of VBA could be OEMs, system integrators and end users
VBA scripts will perform functions like calculations or other minor tasks but the
main power of VBA will be to manipulate application objects
all exposed iFIX objects and their properties, methods, and events
1-4
*()DQXF
ZZZML\LWHFKFRP
Student Guide
VBA Terminology
Objects
Properties
Characteristics of an object
Examples: color, size, location in the picture
Methods
Events
Actions that the object recognizes, such as when a user clicks the
mouse on the object or changes its size
1-5
*()DQXF
1.1.1.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
A. Notes
B. Examples
Figure 1-2 contains the iFIX objects that are available within VBA
C. Additional Notes
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
1-6
*()DQXF
1.1.1.
ZZZML\LWHFKFRP
Student Guide
Alarm Summary
Application
Arc
Bitmap
Chart
Chord
Color Button
ControlContainer
DataItem
DataItems
DataLink
DataServer
DataServers
Document
Documents
DynamoSet
Event
ExpressionEditor
FindReplace
FixDataSystem
FixFloatPoint
Format
Group
Group (DataSystem)
Groups
Legend
Line
Lines
Linear
Lookup
Oval
Picture
Pen
Pie
Polygon
Polyline
Procedures
Rectangle
RoundRectangle
Scheduler
ScriptLine
ScriptProcedure
ScriptSource
Sources
System
Text
TimeAxis
Timer
UserGlobals
ValueAxis
Variable
Window
Figure 1-2: iFIX Objects
1-7
*()DQXF
1.1.2.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Use the Property Window within the WorkSpace to view the properties of an
object
-
Figure 1-3 shows some of the properties of a picture object using the Property
Window
To set the value of a property, follow the reference to an object with a period, the
property name, an equal sign (=), and the new property value
D. Additional Notes
The Help topic for each property indicates whether that property is:
-
read-write
read-only
write-only
1-8
*()DQXF
1.1.2.
ZZZML\LWHFKFRP
Student Guide
1-9
*()DQXF
1.1.3.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
End Sub
Add
BringToFront
Copy
Connect
Enable
FullView
GetCurrentValue
InsertPoint
IsConnected
Open
Refresh
Rotate
ScrollForward
SetWindowLocation
StopTimer
Zoom
Figure 1-6: Sample iFIX Methods
1-10
*()DQXF
1.1.4.
ZZZML\LWHFKFRP
Student Guide
Examples:
the script in Figure 1-4 runs a procedure when a rectangle objects click
event occurs
the script in Figure 1-5 run a procedure when the picture initialize event
occurs
Activated
AlarmAck
Close
Click
ColorChanged
DataChange
DeActivated
DblClick
Edit
EditChange
Initialize
KeyDown
KeyUp
LmouseClick
MouseDown
MouseMove
MouseUp
OnChange
OnChartFull
OnChartRefresh
OnFalse
OnPenSelect
OnTimeOut
OnTrue
RMouseClick
SelectionChanged
UIDeactivate
WhileFalse
WhileTrue
Figure 1-7: iFIX Events
AfterKillFocus
1-11
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
The object that is common to all applications and is at the top of the application
model is the Application Object
The application object is the container for all other objects even other container
objects like the Window object container
All iFIX objects like picture documents, shape objects and more will reside in
WorkSpace
B. Window Object
C. Other Containers
1-12
*()DQXF
ZZZML\LWHFKFRP
Student Guide
1-13
*()DQXF
1.2.1.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
A. Intellution WorkSpace
The iFIX picture document will also contain the VBA script code
Fix2D objects (rectangles, text, lines, and such that make up a picture item)
Groups (named collection of shapes that form valves, pumps, tanks, etc.)
iFIX process database , Historical files, Global variables, OPC servers and other
objects
1-14
*()DQXF
1.2.1.
ZZZML\LWHFKFRP
Student Guide
iFIX Container__________________________________________
Text
iFIX Container
Picture Object
Excel Container
Keyboard
Workbook Object
Mouse
LineObject
Sheet1 Object
RectObject
Sheet2 Object
Modem
TextObject
Object Event VBA Code
NIC
XYZ Container
Serial Port
Form Object
Hard Drive
Container Support Code
Windows NT
1-15
*()DQXF
1.2.2.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
iFIX objects
-
Forms
-
ActiveX Objects
-
1-16
*()DQXF
1.2.2.
ZZZML\LWHFKFRP
Student Guide
For loop, same as While loop, but auto increments a variable each loop
1-17
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
the items that can be a part of the project are user forms, modules, and
references
in the VBE clicking on the Project_untitled will bring the module into
view in the code window of the VBE
Here is a partial list of topics and concepts that are a part of VBA and will be
discussed in the next chapters:
Variables
Constants
Functions
User forms
Looping
Decisions
Debugging
Expressions
Automation
Error Handling
1-18
*()DQXF
ZZZML\LWHFKFRP
Student Guide
1-19
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
F1
Language Reference
MsForms Reference
D. Find Tab
E. Index Tab
Provide a match to keywords that the Help File developer decides was important
1-20
*()DQXF
ZZZML\LWHFKFRP
Student Guide
1-21
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
B. Contents
Subroutines
Database Functions
1-22
*()DQXF
ZZZML\LWHFKFRP
Student Guide
1-23
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
1-24
*()DQXF
ZZZML\LWHFKFRP
Student Guide
1-25
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
VBA Terminology
Project
Module
Procedure
Sub Procedure
VBA Procedure that performs a task but does not return a value
Function
Container
Constant
Variable
Objects
Each object has its own properties, methods, and events that can
be used to write scripts
Properties
Methods
Events
Characteristics of an object
1-26
*()DQXF
1.7.
ZZZML\LWHFKFRP
Student Guide
Introduction to VBA
Lab Exercise 1
1-27
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Work with the help built into the WorkSpace and the VBE
When you are finished with this lab, turn to page 1-38 and answer the Summary Questions.
Resources:
Lab Information
During this section, you were introduced to VBA terminology, how to manipulate objects,
how to create code, and how to use online help. Now you will get an opportunity to create a
point of reference for the future when youre confronted with VBA and iFIX terminology.
To give you some hands on experience with the Visual Basic Editor, we will guide you
through various dialog boxes and windows. You will discover how to open various windows
and get details about the objects you are working with.
If you are looking for help remember that help can be found in the Electronic Books and the
Release Notes. There is also Automation Interfaces Help and Database Manager Help. All
of these can be found in the Help & Information folder of the WorkSpace System Tree. And
of course, if you go to the help menu you can get WorkSpace Help and Picture Help. When
you are working with the Visual Basic Editor, you have access to Microsoft Visual Basic
Help and iFIX Automation Help.
1-28
*()DQXF
ZZZML\LWHFKFRP
Student Guide
2. Can you use iFIX VBA to build a stand-alone application that can be complied down
to an EXE, DLL, or OCX?
3. Since VBA is the same across all applications, you could take the VBA code and the
UserForms you developed in iFIX VBA and drop them into Excel. Can you also take
the VBA code and UserForms you developed in iFIX VBA and drop them into
Microsoft Access? How about Visual Basic itself?
4. In your own words, explain the following terms: properties, methods, and events.
AddItem
Layer
VerticalPosition
FindObject
Click
KeyUp
OnTimeOut
Name
Edit
BuildObject
VerticalFillDirection
AddPen
ClassName
CurrentImage
MouseMove
1-29
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
1. Create a new picture in the WorkSpace and add the following objects:
3 rectangles
1 polyline
1 arc
1 chord
1 oval
2 polygons
1 pie
1 pushbutton
2. Save the new picture by clicking the File menu then Save.
Use the following file name:
VBAObjects
1-30
*()DQXF
ZZZML\LWHFKFRP
Student Guide
3. You see all your new objects in the System Tree on the left-hand side of the
WorkSpace. You can see that all the objects have unique, though uninteresting
names.
4. Go to the View menu and select the Property Window.
The Property Window appears.
5. Note that when you select an object in the WorkSpace work area, the corresponding
object also is selected in the System Tree and in the Properties Window. You can
also select an object in the System Tree, or by using the drop-down menu in the
Properties Window.
Regardless where you select the object (WorkSpace work area, System Tree, or
Properties Window) the corresponding information about the object is highlighted in
the other two locations.
1-31
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
The properties that you just modified in the Properties window can also be modified
with VBA code both at run-time (Run mode) and design-time (Configure mode).
These same properties can have animations assigned to them.
1-32
*()DQXF
ZZZML\LWHFKFRP
Student Guide
2. Take note of the Properties window. Select the pull-down menu and choose
VBAObjects. There are two things to note:
(a) You are looking at the properties page for the picture where you can leave a
description, comment, information about the author, etc.
(b)
3. Right click on the TankFillBarGraph object and select the Edit Script.
4. Now that you are in the VBE, go to the View menu and select Immediate Window
and Properties Window. Your display should look something like this:
5. The VBE should be displaying the Project Explorer in the upper left-hand corner.
Below it should be the Properties Window. The lower right-hand corner should be
the Immediate Window and above it the Code Window. Above the Code Window
on the left-hand side is the VBE Object drop-down list. This is a list of objects that
are registered with the VBE. To the right of it is the Event drop-down list.
1-33
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
4. Now click the Protection tab. Do not change anything here, but be aware that you
can password protect your VBA code so other people can not access it. If someone
were looking at your picture in the WorkSpace and decided to look at your code by
launching the Visual Basic Editor, they would get a prompt that forces them to type in
a user and password.
5. Now, close the Project Properties dialog box by clicking the OK button.
1-34
*()DQXF
ZZZML\LWHFKFRP
Student Guide
You have just inserted a module called Module1. You can change the name in the
Properties window.
2. When you look at your Project Explorer you will see VBAObjects located in the
WorkSpace Application Objects. This is where all your picture event code goes
(this will be explained in more detail in the next chapter). In Modules, you will see
the module you just inserted, Module1. You can change the name to something more
meaningful. Also, you can have many modules.
In general, modules contain functions and subroutines called by the picture event
code or by other functions and subroutines.
1-35
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
3. Next we shift our attention to the Immediate Window. This window is great for
trying out functions and small bits of code. For example, if you want to know how
many days between today and the first day of the century, enter the following:
print DateDiff("d", Now, #January 1 2000#)
4. Finally, we bring our attention to the code window. Double-click on Module1 in the
Project Explorer, and type the following code in the code window:
Public Sub Rotate10degrees()
With VBAObjects.TankFillBarGraph
.RotationAngle = .RotationAngle - 10
End With
End Sub
1-36
*()DQXF
ZZZML\LWHFKFRP
Student Guide
5. Put your cursor on the word Rotate10degrees and press the <F5> key. If you made
any typos, you may have gotten an error message after hitting <F5>. If not, you just
ran your code.
6. Use <Alt><Tab> to go back to the WorkSpace to see what changed. You should see
that the rectangle rotated 10 degrees.
The screen should resemble the following:
You were able to modify the properties of an object in the WorkSpace and the
WorkSpace was not even in Run mode!
1-37
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
1. What are all the different locations you can look to find help with iFIX objects?
2. Can you make changes to your Visual Basic Code while the WorkSpace is in run mode?
Explain.
3. Is the property window in the VBE the same as the one in the WorkSpace?
4. iFIX is built upon Component Architecture. iCore is the glue in the Intellution Dynamics
family of software products. What are the main ingredients that make up our iCore glue?
5. In addition to shape objects, what other things are stored in the picture file (the GRF
file)?
1-38
*()DQXF
ZZZML\LWHFKFRP
Student Guide
2. VBA Environment___________________________________________
Chapter 2
VBA Environment
2-1
*()DQXF
2.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Section Objectives
This section provides an introduction to the VBA environment. The discussion will include
VBA projects. The student will also use the Visual Basic Editor to create VBA script. This
includes the following:
Creating Procedures
Creating Modules
2-2
*()DQXF
ZZZML\LWHFKFRP
Student Guide
2.1. Review__________________________________________________
A. Notes
Projects
-
VBA code can reside as part of the picture document or in other areas such
as Modules, Class modules, and User Forms
Picture documents, Modules, User Forms, and Class modules and all other
supporting VBA components, make up a VBA project
Code Modules
Within the Visual Basic Editor the code displayed is the code module
The code displayed can reside in a user defined Module, the Picture
Document, User Forms or a Class Modules
Procedures
-
2-3
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Right click an object that will contain script and select Edit Script
Project Explorer
-
Properties Window
-
Code Window
-
Immediate Window
-
2-4
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Project Explorer
Code Window
Property Window
Immediate Window
2-5
*()DQXF
2.2.1.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
A. Project Explorer
Open projects list reflects what is open in the application, for example,
WorkSpace
-
Examples:
Pictures
Schedules
Toolbars
Globals
Projects contain open application objects (such as a picture), modules (if you have
created them), and user forms you have built
Saving a project
2-6
*()DQXF
2.2.1.
ZZZML\LWHFKFRP
Student Guide
2-7
*()DQXF
2.2.2.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Includes the name of the property and the current property value
New values can be typed in, selected from a drop down list, or double-clicked
2-8
*()DQXF
2.2.2.
ZZZML\LWHFKFRP
Student Guide
2-9
*()DQXF
2.2.3.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
A. Immediate Window
Used to test some code without having to run the entire project
Allows the developer to test expressions, execute code, change values, and debug
an application
or press CTRL-G
2-10
*()DQXF
2.2.3.
ZZZML\LWHFKFRP
Student Guide
2-11
*()DQXF
2.2.4.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Displays the code modules and other objects such as user forms
To display the module code, highlight the project in the Project Explorer and
perform one of the following:
Press F7
Press SHIFT-F7
Object list
Procedure list
Declarations section
Procedure separator(s)
Procedure(s)
Note: In some VBA books, the Object List and Procedure List are called the
Wizard Bar
C. Procedures
Sub Procedure
Function Procedure
2-12
*()DQXF
2.2.4.
ZZZML\LWHFKFRP
Student Guide
2-13
*()DQXF
2.2.4.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
D. Object List
Pull down list that shows what objects exist for the highlighted project
Change code view mode from all procedures in module to only selected
object procedure
-
Includes (General) which refers to any procedures that are not associated with a
particular object
Example Objects
-
Rect1
Oval1
Polygon1
Group1
CFixPicture
Calendar1
Additional Notes
-
If objects do not exist in the object list but are part of the picture
From the Edit menu, select Select All and then right click Enable
Scripts
2-14
*()DQXF
2.2.4.
ZZZML\LWHFKFRP
Student Guide
2-15
*()DQXF
2.2.4.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
E. Procedure List
Click
Mouse Events
Click, DblClick
MouseDown, MouseUp
MouseMove
Key Events
KeyDown, KeyUp
KeyPress
Initialize Event
Enter Event
Exit Event
Activated Event
De-Activated Event
Additional Notes
-
Example:
Initialize event is available for an iFIX picture object but does not
exist as an event for a rectangle object
2-16
*()DQXF
2.2.4.
ZZZML\LWHFKFRP
Student Guide
2-17
*()DQXF
2.2.4.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
F. Function Procedure
Function procedure typically does not modify its environment but does return a
value
G. Sub Procedure
Sub procedure is allowed to modify its environment but it can not return a value
2-18
*()DQXF
2.2.4.
ZZZML\LWHFKFRP
Student Guide
Function Celsius(fDegrees)
Celsius = (fDegrees - 32) * 5 / 9
End Function
Else
End If
End Sub
2-19
*()DQXF
2.2.4.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
when a new module is imported, all the procedures of that module are
imported
use this same technique to copy sample code from the Help system
2-20
*()DQXF
2.2.4.
ZZZML\LWHFKFRP
Student Guide
2-21
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Allows for message to be sent to the operator and waits for a reply
Displays a message in a dialog box, waits for the user to click a button, and
returns an Integer indicating which button the user clicked
To specify more than the first named argument, use MsgBox in an expression
-
B. Syntax
MsgBox (prompt[, buttons] [, title] [, helpfile, context])
-
prompt Required
buttons Optional
title Optional
if the title is omitted, the application name is placed in the title bar
helpfile Optional
context Optional
2-22
*()DQXF
ZZZML\LWHFKFRP
Student Guide
2-23
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Displays a prompt in a dialog box, waits for the user to input text or click a
button, and returns a String containing the contents of the text box
If the user clicks OK or presses Enter, the InputBox function returns whatever is
in the text box
If the user clicks Cancel, the function returns a zero-length string ("")
To specify more than the first named argument, use InputBox in an expression
-
B. Syntax
InputBox (prompt[, title] [, default] [, xpos] [, ypos] [, helpfile, context])
-
prompt Required
title Optional
default Optional
xpos Optional
ypos Optional
2-24
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Else
MsgBox "No Conversion"
End If
End Sub
2-25
*()DQXF
2.5.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
2-26
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Continue to work with the on-line help built into the WorkSpace and the VBE
When you are finished with this lab, turn to page 2-35 and answer the Summary Questions.
Resources:
The iFIX On-line Help and E-Books
The iFIX Automation On-line Help
Microsoft Visual Basic On-line Help
Lab Information
During lecture you covered the VBA Editor and many of its settings and windows. This lab
will give you some hands-on with the VBA Editor.
Note: Throughout the exercise, the following object naming conventions are used:
Prefix:
Root:
Suffix:
Common prefixes used: Valve Vlv, Pump Pmp, Header Hdr, Level Lvl,
Mixer Mix, Temperature Tmp, Label Lbl, Pipe Pipe, Tank Tank or Tk,
Reactor Rea, Conveyor Cnv, Packaging Station Pkg, Palletizer Plt
Common suffixes used: Group Grp, Polygon Pgn, Polyline Pln, Oval Ovl,
Rectangle Rct, Rounded Rectangle Rrt, Bitmap Bmp, Text Txt, Line Lin
Datalink Lnk, Command Button Cmd, Chord Crd, Arc Arc, Pie Pie
2-27
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
2-28
*()DQXF
ZZZML\LWHFKFRP
Student Guide
3. Using the Property Window, modify the properties of the objects as follows:
Rect1:
Name:
Description:
EdgeWidth:
ForegroundColor:
Tank1Rct
Ingredient Tank#1
4
Blue (16711680)
Line1:
Name:
Description:
EdgeColor:
EdgeWidth:
PipeTk1ToVlv1Lin
Tank #1 Pipe to Transfer Valve
Black (0)
9
Oval1:
Name:
Description:
EdgeWidth:
ForegroundColor:
Vlv1XoutOvl
Valve #1 background
4
Light Gray (12632256)
Polygon1:
Name:
Description:
EdgeWidth:
ForegroundColor:
Vlv1XoutPgn
Valve #1 rotary-valve
4
Dark Gray (8421504)
PolyLine1:
Name:
Description:
EdgeColor:
EdgeWidth:
PipeXoutPln
Transfer Out Pipe
Black (0)
9
2-29
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
4. Next, make sure the center of rotation for your polygon is the actual center of the
polygon. To do this, click on the polygon to select it. Then, click the Object menu
followed by Rotate.
You will see the center of rotation and rotation handles appear.
Center of
Rotation
5. If the center is not in the middle of the polygon, click on the center of rotation, and
while holding down the mouse button, drag the center of rotation to the center of the
polygon.
2-30
*()DQXF
ZZZML\LWHFKFRP
Student Guide
2. Instead of working with the Click event, we want the MouseMove event, so from the
event drop-down menu, select MouseMove.
2-31
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
3. You will now type the MouseMove event code as in the figure below. It is also good
programming practice to use comments, so you will be typing those in also, as you
see fit.
'
'
'
'
When finished, the code window should look something like the following:
2-32
*()DQXF
ZZZML\LWHFKFRP
Student Guide
'
'
'
'
'
our
over the
is
to its
With Vlv1XoutPgn
.RotationAngle = .RotationAngle + 5
End With
End Sub
2-33
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
2-34
*()DQXF
ZZZML\LWHFKFRP
Student Guide
1. In the iFIX object hierarchy, what object serves as the container for all shape objects and
ActiveX controls?
2. As you work with iFIX, you will see that each picture has its own VBA programming
project. Is the VBA programming project a container object? What does it contain?
3. Explain the advantages of cutting and pasting code into a module versus importing an
entire code module.
4. Suppose you create an object in a picture and then task-switch to the VBE. The object
does not appear in the Object List. What can you do to get the object to appear in the
Object List?
2-35
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
2-36
*()DQXF
3.
ZZZML\LWHFKFRP
Student Guide
Chapter 3
Variables and Constants
3-1
*()DQXF
3.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Section Objectives
This section provides an introduction to the concept of variables and constants in VBA. This
includes a look at variable data types, variable arrays, and constants. This includes the
following:
Variables
Arrays
Constants
3-2
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Do not use a space, period (.), exclamation mark (!), or the characters @, &, $, #
in the name
Generally, dont use any names that are the same as the functions, statements, and
methods in VBA
-
B. Notes
For example, two variables named tank within the same procedure can not
be declared
3-3
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
If you use a variable that has not been declared VBA will create it
-
Procedure level
-
Module level
-
Public Scope
-
C. The following is a list of variable data types and recommended characters usage
Boolean
bool
Byte
byte
Currency
cur
Date
dat
Decimal
dec
Double
dbl
Integer
int
Long
lng
Object
obj
Single
sng
String
str
Variant
var
3-4
*()DQXF
ZZZML\LWHFKFRP
Student Guide
3-5
*()DQXF
3.2.1.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Integers ______________________________________________
Byte
-
Integer (Short)
-
Long
-
C. Defining
3-6
*()DQXF
3.2.2.
ZZZML\LWHFKFRP
Student Guide
Scaling factors
Single
-
4 bytes of memory
Double
-
8 bytes of memory
3-7
*()DQXF
3.2.3.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
A. Notes
B. String Concatenation
Use the & operator to build up a single string from several short ones
Example
-
C. String Conversions
Example
mystring = object.name
3-8
*()DQXF
ZZZML\LWHFKFRP
Student Guide
3-9
*()DQXF
3.2.4.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Variant _______________________________________________
The value Empty denotes a Variant variable that hasn't been initialized
B. Note
To determine the data type of a Variant value, use the VarType function
-
In a Variant, Error is a special value used to indicate that an error condition has
occurred in a procedure
-
Error values are created by converting real numbers to error values using the
CVErr function
3-10
*()DQXF
3.2.4.
ZZZML\LWHFKFRP
Student Guide
Variant _______________________________________________
3-11
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
When declaring variables, Dim, Public, Static or Private keywords are used
Strings
(empty)
Dates
Boolean
False
Variants
Empty
User defined data types can be defined to provide a means to store more than one
type of data within a variable
3-12
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Option Explicit
Dim intBeepCount As Integer
Dim dblObjRotAngle As Double
Static intVal As Integer
Public intTotalSales As Integer
Dim strAlarmext1 As String, strAlarmext2 As String
Dim TotHiAlms
3-13
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Implicit Declaration
-
VBA does not require the user to declare a variable before using it
Explicit Declaration
-
Explicit declaration allows for a better choice of data type and for
troubleshooting ease of use
Note:
-
Use Option Explicit declaration to ensure variable name has been declared
3-14
*()DQXF
ZZZML\LWHFKFRP
Student Guide
3-15
*()DQXF
3.3.1.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
A. Recall:
Note:
When used at the module level, the Dim statement is equivalent to the
Private statement
Using the Private statement can make the code easier to read and interpret
When you use the Static statement instead of a Dim statement, the declared
variable will retain its value between calls.
3-16
*()DQXF
3.3.2.
ZZZML\LWHFKFRP
Student Guide
A. Understanding Lifetime
The time during which a variable retains its value is known as its lifetime
The lifetime is based on the how the scope of the variable was declared
C. Variable scope
A variable declared at the module level retains its initialized or assigned value
until it loses scope
A variable declared at the procedure level retains a value until the procedure is
finished running
-
If the procedure calls other procedures, the variable retains its value while
those procedures are running as well
If the Static keyword is used before a Sub or Function statement, the values of all
the procedure-level variables in the procedure are preserved between calls
-
3-17
*()DQXF
3.3.3.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
A. Notes
User-defined data types can contain one or more elements of a data type, an array,
or a previously defined user-defined type
Used at module level to define a user-defined data type containing one or more
elements
See the Help for details on the syntax of the Type statement
3-18
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Type EquipmentLog
ID As Integer
Name As String * 20
Location As String * 30
LastMaint As Date
End Type
Sub CreateRecord()
Dim MyRecord As EquipmentLog
MyRecord.ID = 12003
MyRecord.Name = "Vlv03"
End Sub
Type AlarmType
almNodeName As String
almTagName As String
almDate As Date
almValue As Integer
End Type
3-19
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
A typical variable has only one storage compartment in which it can store
only one value
Refer to the array as a whole when you want to refer to all the values it holds, or
refer to its individual elements
-
For example, to store daily quantities for each day of the year, declare one
array variable with 365 elements, rather than declaring 365 variables
Use the Option Base statement at the top of a module to change the default index
of the first element from 0 to 1
-
strValue
Tank1
arrayValues
Tank1
Tank2
Tank3
Tank4
3-20
Tank5
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Sub FillArray()
Dim dailyQuantity(364) As Integer
Dim intI As Integer
For intI = 0 to 364
dailyQuantity (intI) = 100
Next
End Sub
Option Base 1
3-21
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Think of the array as a matrix, where the first argument represents the rows and
the second argument represents the columns
Example
-
The other way is to assign the array returned by the Array function to a
Variant variable, as shown in Figure 3-13
MsgBox "Data for " & varData(0) & " has been recorded."
3-22
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Sub FillArrayMulti()
Dim intI As Integer, intJ As Integer
Dim sngMulti(1 To 5, 1 To 10) As Single
' Fill array with values.
For intI = 1 To 5
For intJ = 1 To 10
sngMulti(intI, intJ) = intI * intJ
Debug.Print sngMulti(intI, intJ)
Next intJ
Next intI
End Sub
3-23
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
A named item that retains a constant value throughout the execution of a program
User defined constants are declared within a procedure or at the module level
-
Use the Const statement to declare a constant and set its value
3-24
*()DQXF
ZZZML\LWHFKFRP
Student Guide
3-25
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
3-26
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Constant
vbBlack
vbRed
vbGreen
vbYellow
vbBlue
vbMagenta
vbCyan
vbWhite
vbSunday
vbMonday
vbTuesday
vbWednesday
vbThursday
vbFriday
vbSaturday
vbKeyLButton
vbKeyRButton
vbKeyBack
vbKeyTab
vbKeyClear
vbKeyReturn
vbKeyShift
vbKeyControl
vbKeyMenu
vbKeyPause
vbKeyCapital
vbKeyEscape
vbKeySpace
vbKeyPageUp
vbKeyPageDown
vbKeyEnd
vbKeyHome
vbKeyLeft
vbKeyUp
vbKeyRight
vbKeyDown
vbKeySelect
vbKeyPrint
vbKeyInsert
vbKeyDelete
vbKeyHelp
vbKeyF1
Description
Black
Red
Green
Yellow
Blue
Magenta
Cyan
White
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Left mouse button
Right mouse button
Backspace Key
Tab Key
Clear Key
Enter Key
Shift Key
Ctrl Key
Menu Key
Pause Key
Caps Lock Key
Esc Key
Spacebar Key
Page Up Key
Page Down Key
End Key
Home Key
Left Arrow Key
Up Arrow Key
Right Arrow Key
Down Arrow Key
Select Key
Print Screen Key
Insert Key
Delete Key
Help Key
F1 Function Key
Constant
vbKeyNumlock
vbKeyMultiply
vbKeyAdd
vbKeySeparator
vbKeySubtract
vbKeyDecimal
vbKeyDivide
vbCr
vbLf
vbTab
vbCrLf
vbBack
vbOKOnly
vbOKCancel
vbYesNo
vbAbortRetryIgnore
vbYesNoCancel
vbRetryCancel
vbCritical
vbQuestion
vbExclamation
vbInformation
vbDefaultButton1
vbDefaultButton2
vbDefaultButton3
vbDefaultButton4
vbApplicationModal
vbSystemModal
vbOK
vbCancel
vbAbort
vbRetry
vbIgnore
vbYes
vbNo
3-27
Description
Num Lock Key
Multiply sign (*) key
Plus sign (+) key
Enter key
Minus sign () key
Decimal point (.) key
Division sign (/) key
Carriage return char.
Linefeed character
Tab character
Carriage return
linefeed combination
Backspace character
OK button only
OK and Cancel
buttons
Abort, Retry, and
Ignore buttons
Yes, No, and Cancel
buttons
Yes and No buttons
Retry and Cancel
buttons
Critical message
Warning query
Warning message
Information message
First button is default
2nd button is default
3rd button is default
4th button is default
Application modal
message box (default)
System modal
message box
OK button pressed
Cancel button pressed
Abort button pressed
Retry button pressed
Ignore button pressed
Yes button pressed
No button pressed
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
One of the easiest ways of displaying VBA variables in a picture is to use a Text
object in a picture
Within a script, simply set the value of the variable equal to the caption property
of the text object
-
Example
Figure 3-17 shows various uses of the Format function to format values
using both named formats and user-defined formats
For the date separator (/), time separator (:), and AM/ PM literal, the
formatted output displayed depends on the local PC settings
3-28
*()DQXF
ZZZML\LWHFKFRP
Student Guide
MyStr = Format(23)
3-29
*()DQXF
3.7.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
3-30
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Continue to work with the on-line help built into the WorkSpace and the VBE
When you are finished with this lab, turn to page 3-45 and answer the Summary Questions.
Resources:
The iFIX On-line Help and E-Books
The iFIX Automation On-line Help
Microsoft Visual Basic On-line Help
Lab Information
During lecture you covered working with variables. This lab will give you some hands-on
with the VBA Editor and working with variables.
3-31
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
3-32
*()DQXF
ZZZML\LWHFKFRP
Student Guide
This module will contain constants that represent the 4 colors from the system default
color pallet. You will go on to create an array of these color values and
corresponding names.
3-33
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
2. Lets examine this code. At the top we have the Compiler Option, Option Explicit.
When placed at the top of your module, VBA does not allow you to use variables
without declaring them first. Why is this a good thing? It prevents spelling errors
and typos from introducing major problems into your code.
3-34
*()DQXF
ZZZML\LWHFKFRP
Student Guide
AltColorNameStr As String
End Type
2. Again, look at this new code. The user defined data type is very simple - it is simply
the name of a color and the numeric equivalent only two entries in our record.
3-35
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Because we know our array will not change (there are only 4 colors defined in this
exercise), we use a fixed-size array.
2. By now youve noticed the suffixes on the variables we have presented. In Visual
Basic, it is common to find these extensions used as prefixes. You can choose to
follow either convention, or you can choose not to append any data type indicator to
your variables. What ever you choose, the most important thing is that you stick with
your convention throughout your entire application.
3-36
*()DQXF
ZZZML\LWHFKFRP
Student Guide
4. This new code module has two functions. These two functions are public so that we
can call them from anywhere inside the project. You will find it necessary later in
this lab to call these functions from the event code of your picture
The function NewColor simply returns the next color in our array of colors.
Function ColorName takes the value of a color as an argument and returns the color
name if there is a match.
Functions and procedures will be covered in more detail later in the course.
3-37
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
The code for this imported module should resemble the following:
3-38
*()DQXF
ZZZML\LWHFKFRP
Student Guide
2. Name the procedure InitializeColorArray. To write the VBA code you need to
know the name of the array and the name of the two data types you will be setting.
You will be setting four elements of the array. You will have to do this twice within
the procedure. Once for the default color, and once for the default color name.
Hints:
arrayname(element).variablename = default
Add the following line as the last line in your procedure. This will preset the
index to 1 which is the color red
FdColorIndexByt = 1
3-39
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
3. To run the code when the picture opens , type the name of public sub procedure
InitializeColorArray in the CFixPicture Initialize event, as shown below:
3-40
*()DQXF
ZZZML\LWHFKFRP
Student Guide
4. Use the VBE Object drop-down list to select Tank1Rct, and use the Event dropdown list to select the Click event. Here, type the code that will change the
foreground color of our rectangle to a new color each time it is clicked. The code will
look something like the following:
Private Sub Tank1Rct_Click()
Tank1Rct.ForegroundColor = NewColor
End Sub
5. Again use the Event drop-down list, this time to select the DblClick event. Here type
the code that will change the edge color of our rectangle to a new color. Hint, this
code will be very similar to the previous step.
3-41
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
2. How will we do this? First, we look into the on-line help to see what the arguments
for the KeyUp event do. We find that KeyCode returns the value of which key was
pressed, so if we want to test for the <spacebar> we would have a statement like:
3. Next, we see the message box. Again we go to the on-line help to look up the
arguments for the MsgBox. If we want to display a message and prompt the operator
for a yes/no input, we would have a statement like:
4. Next, we need to determine how to concatenate the message string. This is easy. We
first declare a local (not public) string variable like MessageStr. Then we set it equal
to our strings and properties using the ampersand ( & ) to concatenate everything.
But how do we put information on separate lines? Well give you a hint: Chr$(13).
Feel free to return to on-line help to see what this does.
5. Dont forget that .ForegroundColor and .EdgeColor return numeric values, not
names of colors. How do we convert the numeric values to names? We would have a
statement like: ColorName(.ForegroundColor). If you recall, ColorName is a
public function in the module we created.
3-42
*()DQXF
ZZZML\LWHFKFRP
Student Guide
6. What happens if the operator hits Yes? You will want to set the .ForegroundColor
= FdBrightBlueCLng, set the .EdgeColor = FdBlackCLng, and finally reset the
tank level with a statement like: .VerticalFillPercentage = 100
The entire procedure could look something like the following:
3-43
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
3-44
*()DQXF
ZZZML\LWHFKFRP
Student Guide
1. If you want to set a variable to a property value, you should make sure both are the same
type, for example integer. How do you determine what data type a property is?
2. How do you create user-defined data types and why would you use them? Give
examples.
3. How do you create an array? What do you do if you dont know the size needed for the
upper bound of the array?
4. What is the purpose of the Option Base command when creating an array?
3-45
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
3-46
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Chapter 4
Procedures and Functions
4-1
*()DQXF
4.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Section Objectives
This section provides an introduction to the different types of Procedures. The Object Browser
will be used to find out information on an objects properties, methods and events. Students will
work with VBA sub procedures and functions. This includes the following:
VBA References
Expressions
Object Browser
4-2
*()DQXF
4.
ZZZML\LWHFKFRP
Student Guide
4-3
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
iFIX automatically creates a references to its own object libraries when an object
is added to a Workspace project and edited in the VBE
To add a new reference highlight the project in the VBE in which the objects
reference will be used
-
From the Tools menu, select References and check the new library from
list
The available list is based on the application installation and registry settings
-
4-4
*()DQXF
ZZZML\LWHFKFRP
Student Guide
4-5
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Function procedures
Or, select the object in the iFIX WorkSpace right click it and select edit script
-
Or, just start typing using proper syntax in the VBE workspace
-
4-6
*()DQXF
ZZZML\LWHFKFRP
Student Guide
4-7
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
E. Predefined Procedures
Examples:
InputBox displays a dialog box that accepts data from the user
4-8
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Function Celsius(fDegrees)
Celsius = (fDegrees - 32) * 5 / 9
End Function
sngX = Rnd
Beep
4-9
*()DQXF
4.2.1.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
A. Notes
Examples:
-
Event procedures can be written in a picture code module or a form code module
MouseDown
MouseUp
Click
DblClick
MouseUp
-
4-10
*()DQXF
4.2.1.
ZZZML\LWHFKFRP
Student Guide
Event
Occurs when
Activated
AfterKillFocus
AlarmAck
an alarm is acknowledged.
Click
the user releases the left mouse key in the Run-time environment.
Close
ColorChanged
DataChange
DblClick
DeActivated
Edit
the user double clicks an object in the Configuration environment, or the user
pastes an object into a page from a Dynamo Set.
EditChange
the text in the edit box portion of the Expression Editor is changed.
Initialize
KeyDown
KeyUp
LmouseClick
the user clicks the left mouse button on the Alarm Summary object in the
Configuration or Run-time environment.
MouseDown
MouseMove
MouseUp
OnChange
OnChartFull
the data for a Chart object scrolls all the way to the right and hits the edge when
the ScrollDirection property is set to LeftToRight
OnChartRefresh
the Chart object's data automatically scrolls. The event occurs at an interval
defined by the RefreshRate property.
OnFalse
OnPenSelect
the user changes the currently active Pen by selecting another Pen.
OnTimeOut
a Timer Objects timeout period expires based on the TriggerType of the Timer.
OnTrue
RMouseClick
the user clicks the right mouse button on the Alarm Summary object in the
Configuration or Run-time environment.
WhileFalse
the value of an Event object is zero. This event is called back at an interval
specified by the Interval property of the Event object.
WhileTrue
the value of an Event object is non-zero. This event is called back at an interval
specified by the Interval property of the Event object.
4-11
*()DQXF
4.2.2.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Understanding Scope___________________________________
A. Scope of a Procedure
private module-level
public module-level
B. Private Procedures
Private means the procedure can only be used inside its own module
C. Public Procedures
Public means other projects can use the procedures or functions as well
-
D. Setting the scope for functions and sub procedures can be done when defining each
procedure or once at the top of the module for all procedures
For a individual procedure include the keyword private or public in the procedure
name definition
For all, set Option Private Module (or public) at the top of the module
-
4-12
*()DQXF
4.2.2.
ZZZML\LWHFKFRP
Student Guide
Understanding Scope___________________________________
Option Explicit
Public Sub CFixPicture_Initialize()
Dim fixalarms As CfixAlarms
Set fixalarms = New CfixAlarms
End Sub
Text1.Caption = fixalarms.NodeName
End Sub
4-13
*()DQXF
4.2.3.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
When using the optional keyword the function isMissing can be used in the VBA
code to determine if the argument was passed or not
B. Arguments can be passed to the procedure in the order they appear in the procedure
definition or by name
Passing the argument in the defined order just requires the values to be passed
separated by a comma
Passing the argument by name requires using the argument name, followed by a
semi colon, followed by an equal sign and then the value
4-14
*()DQXF
4.2.3.
ZZZML\LWHFKFRP
Student Guide
DoEvents
Loop
End Sub
For counter = 1 To 10
'display the counter message
Application.StatusBar = "Counter Value: " & counter
txtcount.Caption = "Counter Value: " & counter
mywait (5)
Next counter
End Sub
4-15
*()DQXF
4.2.3.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
D. Pass by Reference
arguments passed by reference take the same amount of time to pass and
the same amount of space within a procedure regardless of the data type
E. Pass by Value
Any changes made to the variable only affect that procedure using it
Changes to the argument within the procedure are not reflected back to the
original variable
Larger data types take slightly longer to pass by value than smaller ones
Because of this, String and Variant data types generally should not
be passed by value
F. Example
4-16
*()DQXF
4.2.3.
ZZZML\LWHFKFRP
Student Guide
Dim S As Integer
S = 5
Debug.Print Factorial(S)
Debug.Print S
End Sub
4-17
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Mathematical calculations
Compare values
4-18
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Assignment operator
Arithmetic operators
+, -, *, /, \, ^, Mod
Comparison operators
Logical operators
Concatenation operator
&
4-19
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Math functions
-
Financial functions
-
String functions
-
Format function
-
E. Example
4-20
*()DQXF
ZZZML\LWHFKFRP
Student Guide
4-21
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
In other projects
-
B. Before creating code, decide where the code should reside by considering the following:
4-22
*()DQXF
ZZZML\LWHFKFRP
Student Guide
4-23
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Class modules and regular code modules are both just a place in which to write
code but differ in what code is inside the module
-
Class modules are an extension of user defined data types discussed in the
Variables section
Instead of static data that makes up a user defined data type a Class Module will
represent a new object with its own characteristics
The Class module will contain code that defines a template for a new object and
its properties and methods
-
The Class module does not contain the object but rather creates it when
the code is invoked
When all is done the new object can be used like any other object accessing and
changing its properties and using its methods
4-24
*()DQXF
ZZZML\LWHFKFRP
Student Guide
4-25
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
After declaring a new object members are added to represent the properties
D. VBA code that creates a class object and its changeable properties
Let procedure lets the user assign new values to the properties
Option Explicit
4-26
*()DQXF
ZZZML\LWHFKFRP
Student Guide
End Property
End Property
End Property
4-27
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Objects have their own set of properties, methods and events which can be used to
control the object
B. The Object Browser will help to keep track of all the objects in a Object Model
C. Notes
The available object libraries reflect available references that are checked in the
VBE Reference list
4-28
*()DQXF
ZZZML\LWHFKFRP
Student Guide
4-29
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Example foreground
Classes window
-
Members window
4-30
*()DQXF
ZZZML\LWHFKFRP
Student Guide
4-31
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Allows for the specification of an object or user-defined type once for an entire
series of statements
-
With statements can be nested by placing one With block within another
B. Example:
place the property assignment statements within the With control structure
Figure 4-19 illustrates use of the With statement to assign values to several
properties of the same object
4-32
*()DQXF
ZZZML\LWHFKFRP
Student Guide
With MyObject
.Height = 100
.Caption = "Hello"
With .Font
.Color = Red
.Bold = True
End With
End With
4-33
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
B. Code View
Use the Procedure View and Full Module View buttons at the bottom of the Code
Window
-
C. Split Window
Dragging this bar down, splits the Code window into two horizontal panes, each
of which scrolls separately
-
This allows for viewing of different parts of the code at the same time
The information that appears in the Object box and Procedures/Events box applies
to the code in the pane that has the focus
Dragging the bar to the top or the bottom of the window or double-clicking the
bar closes a pane
D. Formatting Code
4-34
*()DQXF
ZZZML\LWHFKFRP
Student Guide
F. List Properties/Methods
G. List Constants
When entering functions that accept enumerated values as parameters, VBA can
list available constants
H. Parameter Information
When entering parameters into functions, VBA can display a list of the
parameters, data types, and any default values
I. Word Completion
4-35
*()DQXF
4.7.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Multiply the area inside the tank with the current height to get the volume
Be sure to add the value of the total volume of the tapered end!
9
h + 10 , where h = the level of the tank
14
V = (r 2 )(h 70)
h( Ra 2 + ( Ra )( Rb ) + Rb 2 )
3
90 2 27 3
= (100 h +
h +
h )
14
196
V =
= (3025)( h 70)
Figure 4-20: Formula for Volume of
a Cylinder (top part of tank)
4-36
*()DQXF
4.7.
ZZZML\LWHFKFRP
Student Guide
110
100%
Level Transmitter
90
Rb
Ra
0%
20
4-37
70
*()DQXF
4.8.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Mathematical Functions
Lab Exercise 4
4-38
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Revisit some of the naming conventions talked about in the previous lab.
Build your own math functions for converting between English and Metric
units
When you are finished with this lab, turn to page 4-49 and answer the Summary Questions.
Resources:
Lab Information
During lecture you covered the Object Browser, working with procedures, building
expressions, numeric variable data types. This lab will give you plenty of hands-on with the
VBA Editor, working with variables, building expressions, and working with function
procedures.
You will be helped along with some hints but for the most part you will be left to your own
devices.
4-39
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
4-40
*()DQXF
ZZZML\LWHFKFRP
Student Guide
2. Switch to Run mode and you can see that some of the functionality exists.
(b)
(c)
The Actual Level and the Volume values never change this is the goal of this
exercise
(d)
As you move the mouse over the tank, the level decreases. Double click the
tank to fill it. Or you can manually enter a percentage in the text object.
(e)
As you move the mouse over the thermometer, the temperature increases.
Double click the thermometer to set the temperature to 60. Or you can
manually enter a temperature in the text object.
4-41
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
3. With the WorkSpace in Run mode, from the Workspace menu, select Visual Basic
Editor.
The screen should resemble the following:
Make sure the current project selected in the Project Browser is the WaterTank
picture.
4-42
*()DQXF
ZZZML\LWHFKFRP
Student Guide
4. Because the relationship between the level transmitter (0 to 100) is linear with the
level of the tank (0 to 160), it is easy to determine the level of the tank in centimeters.
Use the following formula:
8
centimenters = percent
5
PercToCm = (8 / 5) * percent
End Function
4-43
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
80
4-44
*()DQXF
ZZZML\LWHFKFRP
Student Guide
(b)
Takes this new value and sets it equal to the caption of the Actual Level text
object.
Hints: This new code is event code, not simply some function.
Make sure you put the code in the correct place. It belongs in the picture
module.
Use the Text objects caption property
This procedure can be completed in one line of code!
4. When you feel this is working correctly, move on to the next page.
4-45
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Volume = (100 h +
90 2 27 3
h +
h )
14
196
Hints: Use the PercToCm function as a model when creating these two functions.
Both of these functions use . If you want the easy way out, just create a
variable for equal to 3.14159. Or, if you want a more accurate answer, use
the on-line Help to get a better value for !
4-46
*()DQXF
ZZZML\LWHFKFRP
Student Guide
4. Now, the easy part is determining the height of the whole tank, right? Well, not quite.
Remember, we need to determine if the level of the tank is greater than 70 or not. If
it is less than 70, we simply use the cone volume. If the level is greater than 70, we
use the cylinder volume and add in the full cone volume. The code for this will look
something like this:
Public Function volumeTank(ByVal h As Double)
If h <= 70 Then
volumeTank = volumeCone(h)
Else
volumeTank = volumeCone(70) + volumeCylinder(h)
End If
End Function
5. Test your formula in the Immediate window. Here are a few test cases for you to try:
volumeCone (70) =
269,391.57
volumeCylinder (160) =
855,298.60
volumetank (160) =
1,124,690.17
volumetank (0) =
0.00
6. Now, go back to the WorkSpace configure mode. Create an event script such that,
when the user clicks on the text object displaying the volume, the value is updated.
Obviously, you will need the functions you just created.
Hints: This new code is event code, not simply some function.
Make sure you put the code in the correct place.
Use the Text objects caption property
This procedure can be completed in one line of code!
Use the previous example as a model.
7. Save your picture when finished.
4-47
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
3. Create a push button on the screen to change the temperature displayed in the link
between Celsius and Fahrenheit. The conversion function is in a Module within the
WaterTank project. Make sure to change the text label too!
4. After completing the step above, have the same pushbutton change the level to
display values in inches and display volume in gallons. The conversion function is in
a Module within the WaterTank project. Make sure to change the text label too!
4-48
*()DQXF
ZZZML\LWHFKFRP
Student Guide
2. How can you set the scope for a function or sub procedure? Is there a way to make a
function or sub procedure global / accessible to all pictures?
3. Lets say you needed to work with a function such as inverse cosine. You quickly
discover that inverse cosine does not exist as a function in VBA. How do you derive the
function for inverse cosine? (Hint take a look at the on-line help).
4. What is the difference between division using the forward slash / and division using
back slash \ ?
5. VBA is very forgiving when it comes to data type conversion. If you dont specify the
proper data type, VBA will do the conversion for you, although not always the way you
might expect. There is a special set of functions to handle conversion between type
what are these functions?
4-49
*()DQXF
4.9.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
4-50
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Section 5
VBA Debugging
5-1
*()DQXF
5.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Section Objectives
In this section you will become familiar with how to use the debugging tools of the Visual Basic
Editor. Topics to be discussed in this section include the following:
Syntax errors
Common errors
Immediate window
Watch window
5-2
*()DQXF
ZZZML\LWHFKFRP
Student Guide
5.1. Review__________________________________________________
A. Project Structure
Projects
-
VBA code within a project can reside in Modules, Class modules, and/or
user forms
Code Modules
-
Module code can exist in the picture document, user defined modules or
Class modules
Procedures
-
Project Explorer
-
Properties Window
-
5-3
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Standard
Edit
Debug
UserForm
B. Menu Bar
From the View menu, select Toolbars, and select the Commands Tab
-
5-4
*()DQXF
ZZZML\LWHFKFRP
Student Guide
5-5
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Syntax errors
-
Compile errors
-
Runtime errors
-
these errors can be dealt with using Error Handlers, which is covered later
in the course
Logic errors
-
Pausing a procedure
Watch Window
Breakpoints
Immediate Window
Locals Window
Quick Watch
Call Stack
5-6
*()DQXF
ZZZML\LWHFKFRP
Student Guide
5-7
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
5-8
*()DQXF
ZZZML\LWHFKFRP
Student Guide
5-9
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Combined with the debugging windows you can monitor values in your statement
The script stops before running the statement at which the breakpoint exists
B. Using breakpoints
Place cursor on statement and from the Debug menu, select Toggle
Breakpoint
When breakpoint reached during execution, the program halts and VBE is
displayed
5-10
*()DQXF
ZZZML\LWHFKFRP
Student Guide
5-11
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Press F8, or
Note: Called procedure still runs normally you just dont step through it
Step to the procedure you want to step over or set a breakpoint at the procedure
Press SHIFT-F8, or
C. Stepping Out allows you to get out of a procedure without stepping through it
Press CTRL-SHIFT-F8 or
5-12
*()DQXF
5.5.1.
ZZZML\LWHFKFRP
Student Guide
5-13
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
C. The Immediate can also be used as a place to send information while script executes
Use the Call keyword to call a sub routine from the Immediate Window
D. Additional Notes
5-14
*()DQXF
5.5.2.
ZZZML\LWHFKFRP
Student Guide
End Function
5-15
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Highlight item in script and drag and drop into watch window
Variables
Constants
Property values
Functions
Operators
Object values
5-16
*()DQXF
5.5.3.
ZZZML\LWHFKFRP
Student Guide
5-17
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
SHIFT-F9 or
5-18
*()DQXF
5.5.4.
ZZZML\LWHFKFRP
Student Guide
5-19
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Dockable
Floating
5-20
*()DQXF
5.5.5.
ZZZML\LWHFKFRP
Student Guide
5-21
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
B. From the View menu, select Call Stack or the click the ellipsis button in the Locals
Window
5-22
*()DQXF
ZZZML\LWHFKFRP
Student Guide
5-23
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Comment lines begin with an apostrophe (') or with Rem followed by a space
-
B. Indenting
All lines in the selection are moved the same number of spaces to retain
the same relative indentation within the selected block
Change the tab width on the Editor tab of the Options dialog box
C. Bookmarks
Use the bookmark tool to mark as many areas in the code as you want
-
the bookmark tools allow for quick searches to the next or previous
bookmark in a code module
5-24
*()DQXF
ZZZML\LWHFKFRP
Student Guide
5-25
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
CTRL-SHIFT-F9
If an expression is highlighted before opening the Add Watch dialog box, VBA
will automatically fill in the Expression field with the highlighted expression
Alternatively:
Use the comment tool to comment out all the statements in a procedure
5-26
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Key Stroke
Description
F1
F2
SHIFT+F2
CTRL+SHIFT+F2
F3
Find Next: repeat text search down through your code. If no text search
has been done, the Find dialog box is displayed.
SHIFT+F3
Find Previous: repeat text search up through your code. If no text search
has been done, the Find dialog box is displayed.
F4
F5
ALT+F5
Runs the error handler code or returns the error to the calling procedure.
Does not affect the setting for error trapping on the General tab of the
Options dialog box.
F6
F7
CTRL+F7
F8
ALT+F8
SHIFT+F8
F9
CTRL+SHIFT+F9
SHIFT+F10
5-27
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Key Stroke
Description
CTRL+C
CTRL+G
CTRL+I
CTRL+SHIFT+I
CTRL+J
CTRL+J
CTRL+SHIFT+J
CTRL+K
CTRL+V
CTRL+X
CTRL+Y
CTRL+Z
CTRL+SPACEBAR
Key Stroke
Description
SHIFT+CTRL+ALPHA
ALPHA
CTRL+CLICK
CLICK+DRAG
SHIFT+CLICK
CTRL+CLICK+DRAG
5-28
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Key Stroke
Description
CTRL+BACKSPACE
CTRL+BREAK
DELETE or DEL
CTRL+DELETE
END
CTRL+END
HOME
CTRL+HOME
PAGE DOWN
CTRL+PAGE DOWN
PAGE UP
CTRL+PAGE UP
TAB
CTRL+TAB
SHIFT+TAB
SHIFT+TAB
Key Stroke
Description
CTRL+DOWN ARROW
CTRL+UP ARROW
CTRL+RIGHT ARROW
CTRL+LEFT ARROW
5-29
*()DQXF
5.8.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Debugging Techniques
Lab Exercise 5
5-30
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Practice using the VBA debugging tools on code created in a earlier exercise
When you are finished with this lab, turn to page 5-41 and answer the Summary Questions.
Resources:
The iFIX On-line Help and E-Books
The iFIX Automation On-line Help
Microsoft Visual Basic On-line Help
Lab Information
During the lecture you were introduced to the debugging tools that are used with VBA. This
lab will give you plenty of hands-on work with these tools.
5-31
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
2. Switch to Run mode and make sure the picture works correctly.
3. Open the VBE and look at the three code modules associated with this picture. They
are:
WaterTank
Conversions
TankCalcs
5-32
*()DQXF
ZZZML\LWHFKFRP
Student Guide
4. The code for TankCalc should resemble the following (but dont worry if it is not
exactly like this):
Public Function PercToCm(ByVal Percent As Double)
PercToCm = (8 / 5) * Percent
End Function
End Function
End Function
Note that the comments have all been removed to conserve space, but you should be
sure to document your code clearly! That is a great debugging tool too!
5-33
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
5. Now, experiment with some of the debugging tools discusses in this chapter. Be sure
to try the following:
Setting Breakpoints
Stepping into/through code
Immediate Window
Locals Window
Watch Window
Using Bookmarks
VBE Call Stack
5-34
*()DQXF
ZZZML\LWHFKFRP
Student Guide
5-35
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
1. The debug stopped in the InitializeColorArray procedure. The first thing we want to
do is find out information using the Locals window.
2. Open the Locals window and you should see the ColorAssign module with a plus
sign. You can click on the plus sign to see the initialized values.
3. Notice anything in the window seeming out of place? Fix the problem.
5-36
*()DQXF
ZZZML\LWHFKFRP
Student Guide
1. To make sure the problem is fixed and it no longer dumps to debug, return to
WorkSpace configure mode then back to Run mode to re-initialize.
2. Because the code will no longer stop on its own, a breakpoint must be set. Many
times you may want to force the code to stop. In this case we want to look at the
information after initialization to ensure the code did what we wanted.
3. To set a breakpoint, open the VBE and double click on ColorAssign module to bring
the code into View. Scroll down to the InitializeColorArray code.
4. Place a breakpoint at the End Sub statement in this procedure. This will bring up the
VBE directly after initialization.
5. Return to WorkSpace Configure mode than to Run mode and the VBE should pop up.
Check the results.
6. Check the Locals window again to ensure the initialization information is now correct
and the erroneous entry no longer exists in the Locals window.
7. Remove breakpoint.
5-37
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
1. Now that our picture is initializing correctly, check to see if the colors change when
the Tank1Rct is clicked
2. Notice it turns Red but not any other colors. We may want to check the actual value
using the Watch window then step through code to find more information.
3. Open the VBE then from the Debug menu add a Watch window. For the expression
add the picture name IngredientTanked. For the procedure and module select All.
4. Notice in the Watch window there is a plus sign on IngredientTanked. Drill down to
Tank1Rct and ForegroundColor to find current color.
5. We now know the color value of Tank1Rct is 255(Red) which of course we could see
but we now know how to find the value using the Watch window.
5-38
*()DQXF
ZZZML\LWHFKFRP
Student Guide
4. Place the cursor on the first line of the NewColor function on top of the text
FdColorIndexByt. The intellisense will show the current value.
5. Continue to step through the code a number of times emulating multiple clicks.
6. To track this better, highlight the text FdColorIndexByt and drag it into the Watch
window. This will make it easier to track.
5-39
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
1. The definition function points to where in the code a variable or constant is defined.
If it does not recognize it the variable has not been defined or misspelled. To try this,
highlight FdColorIndexByt. Go to the VBE View menu and select Definition.
2. That is strange - it seems it is not recognized. This is a variable that needed to be
defined somewhere!
That explains something else. Notice in the Watch window, what type
FdColorIndexByt is. A Variant! Do we want it to be a Variant? No!
VBA makes a variables type a Variant if it does not know the type or Option
Explicit is not set and it creates new variables on the fly even if a spelling error
occurs.
3. This is a clue that Option Explicit was not used and the variable definition is
spelled wrong. Check this out in the ColorAssign module where FdColorIndexByt
is defined.
4. Its those little things. Now if the variable name was fixed. Step through the code
you should see the indexing work 1-4, and the color values change.
All this can be seen from the Watch window without having to go to the WorkSpace
to test.
5-40
*()DQXF
ZZZML\LWHFKFRP
Student Guide
1. What is a breakpoint? How are they added? How can they be used?
2. One could argue that Quick Watch Expressions are not often needed when debugging
VBA code. Why is this?
3. Which window can be used to watch the value of a variable change while the script is
running?
5-41
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
5-42
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Section 6
Introduction to Forms
6-1
*()DQXF
6.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Section Objectives
In this section you will become familiar with these Microsoft Forms and Entry objects supplied
via the VBA engine. Topics to be discussed in this section include the following:
VBA MSForm
Form Controls
6-2
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Label
Windows NT
iFIX Container
Keyboard
Mouse
NIC
Modem
Serial Port
Text Object
Label Object
Button Object
Scheduler Project1
Scheduler
FIX32 Database
6-3
Hard Drive
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
The forms object is actually a collection object containing controls that provide
a means of user interaction with the application
-
Forms are separated from the picture document in the VBE project
6-4
*()DQXF
ZZZML\LWHFKFRP
Student Guide
6-5
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Forms have their own set of properties, methods and events that will be used to
manipulate the form and from controls
Using sizing controls on toolbar to center, make same size and align
6-6
*()DQXF
ZZZML\LWHFKFRP
Student Guide
6-7
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
these controls are components that are added to a form to exhibit some
behavior when the form is run
Then click on the form in the upper left corner of the item's initial position
Hold the mouse down and drag the control to the desired size
Select Object
Label
Text Box
Combo Box
List Box
Check Box
Option Button
Toggle Button
Frame
Command Button
Tab Strip
MultiPage
Scroll Bar
Spin Button
Image
6-8
*()DQXF
6.2.1.
ZZZML\LWHFKFRP
Student Guide
A. Select Objects
Select Objects is the only item in the Toolbox that doesn't draw a control
Select it to resize or move a control that has already been drawn on a form
B. Label
Properties
-
Name is the name used by any VBA script or Tab order efforts
C. Text Box
Properties
Name is the name used by any VBA script or Tab order efforts
6-9
*()DQXF
6.2.1.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
D. Command Button
Command Buttons are typically used to accept selections in the forms or to cancel
without any changes
Properties
If cancel property is true the button is selected when user presses Esc
If default property is set to true the button is selected when user presses
Enter
This form shows a pre defined list of directories with an accept button and
a cancel button
6-10
*()DQXF
6.2.1.
ZZZML\LWHFKFRP
Student Guide
Unload Me
End Sub
6-11
*()DQXF
6.2.1.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
E. List Box
Pre configure the selections available or allow other VBA script to set using the
additem method
Properties
Example
-
F. Check Box
Use a CheckBox to give the user a choice between two values such as Yes/No,
True/False, or On/Off
If the user does not select the CheckBox, it is empty and its setting is No,
False, or Off
If a CheckBox is bound to a data source, changing the setting changes the value of
that source
A disabled CheckBox shows the current value, but is dimmed and does not allow
changes to the value from the user interface
6-12
*()DQXF
6.2.1.
ZZZML\LWHFKFRP
Student Guide
6-13
*()DQXF
6.2.1.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
G. Frame
Controls inside a frame are treated as a unit, moving the frame moves the controls
Properties
-
Name is the name used by any VBA script or Tab order efforts
H. Option Buttons
Properties
I. Toggle Buttons
Properties
-
6-14
*()DQXF
6.2.1.
ZZZML\LWHFKFRP
Student Guide
J. Image
*.bmp
*.ico
*.cur
*.jpg
*.gif
*.wmf
Figure 6-12: Example showing Frame, Option Button, Toggle Button, and Image
6-15
*()DQXF
6.2.1.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
K. Combo Box
The ComboBox combines the text box with the list box
-
Properties
-
L. Spin Buttons
Code can be written that uses the SpinButton to update the displayed value of
another control
6-16
*()DQXF
6.2.1.
ZZZML\LWHFKFRP
Student Guide
SpinButton1.Value = 50
SpinButton1.Max = 100
SpinButton1.Min = 0
End Sub
TextBox1.Text = SpinButton1.Value - 1
End Sub
TextBox1.Text = SpinButton1.Value + 1
End Sub
6-17
*()DQXF
6.2.1.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
M. Scroll Bars
Used by themselves will allow the user to select a value between a predefined
minimum and maximum value
Properties
-
LargeChange returns or sets the amount the value changes when user
clicks between scroll bars
SmallChange returns or sets the amount the value changes when user
clicks one of the scroll arrows
N. Tab Strips
O. MultiPage
Shows a new set of controls each time the user selects a tab
6-18
*()DQXF
6.2.1.
ZZZML\LWHFKFRP
Student Guide
6-19
*()DQXF
6.2.2.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Adding pages to it
To add a new page, simply right click an existing tab and choose New Page
Rename the tab by right clicking the tab and selecting Rename
When a page is added, a Select Objects tool is always available on the page
To add a new control to a page, simply right click a blank part of the page and
choose Additional Controls
-
6-20
*()DQXF
6.2.2.
ZZZML\LWHFKFRP
Student Guide
6-21
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Click event can be used in a button or any other object in a iFIX picture
The event code can launch the form by using the forms Show method
Key event can be any key on the keyboard like F5 and can be defined to a single
picture document or across all picture documents
Edit event can be used to launch form from the VBE for testing
Note that forms are modal, forms must be unloaded or hidden before any other
user events take place
UserForm1.Show
End Sub
6-22
*()DQXF
ZZZML\LWHFKFRP
Student Guide
VBA code can monitor and react to events once the form is displayed
Initialize
-
Activate
-
Deactivate
-
Terminate
6-23
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
When modal the user must respond before using any other part of the
application
B. Understanding Me
Use the Me keyword to refer to the current instance of the object where the code
is running
All procedures associated with the current object have access to the object
referred to as Me
Using Me is particularly useful for passing information about the current instance
of an object to a procedure in another module
Example:
-
6-24
*()DQXF
6.6.
ZZZML\LWHFKFRP
Student Guide
Using Forms
Lab Exercise 6
6-25
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
When you are finished with this lab, turn to page 6-38 and answer the Summary Questions.
Resources:
Lab Information
The first part of the lab will work create a more complex form that will contain option
buttons, check boxes, frames, and more.
The second form you create will allow you to display any combination of sets of objects.
This is done using layers. We will guide you through information that talks about layers.
6-26
*()DQXF
ZZZML\LWHFKFRP
Student Guide
6-27
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
6-28
*()DQXF
ZZZML\LWHFKFRP
Student Guide
When finished, the form you will create will look like the following:
Use this picture as a model as you add controls to the form. It is very important to
use the object names as defined in the exercise. Otherwise, the code samples will not
work correctly.
2. Add the following Controls to the to the form. Use the names provided below.
Hints:
(a)
(b)
Make the form larger than needed to format the form easier. When finished,
reduce the size to make a reasonable size.
Control
Name
Caption
Frame
fraTank
Tank
Frame
fraEquipment
Equipment
Frame
fraAction
Action
Option Button
optTank1
Tank 1
Option Button
optTank2
Tank 2
Option Button
optTank3
Tank 3
6-29
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
3. Continue adding Controls to the to the form. Use the names provided.
Control
Name
Caption
Option Button
optBulk
Bulk
Option Button
optReclaim
Reclaim
Option Button
optMixTank
Mix Tank
Option Button
optReactor
Reactor
Option Button
optValve
Valve
Option Button
optPump
Pump
Option Button
optMixer
Mixer
Check Box
chkRepaired
Repaired
Check Box
chkReplaced
Replaced
Check Box
chkCalibrated
Calibrated
Text Box
txtName
Name:
Combo Box
cmbCause
Cause:
Command Button
cmdSend
Send
Command Button
cmdCancel
Cancel
Command Button
cmdHelp
Help
4. Change the Send button so the caption appears disabled. Hint: Think about which
property is needed to accomplish this. No scripting is needed.
6-30
*()DQXF
ZZZML\LWHFKFRP
Student Guide
This code simply declares a few String variables. These variables will be used to
store the selected information on the form.
This procedure will be called from the Send button and the Cancel button. It is used
to display information to the WorkSpace status bar and to a Message Box.
6-31
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
4. Add a procedure to the form code module. The procedure will enable the caption of
the Send button when the Repaired Check Box is selected.
5. Create two similar procedures for the Replaced Check Box and the Calibrated
Check Box.
The screen should resemble the following:
6-32
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Msg1LineStr = Msg1Str
Msg3LineStr = Msg1Str
Call WriteLog
Unload Me
End Sub
This procedure is called when the Cancel button is selected. The procedure simply
gathers the current form selections, displays the information using the WriteLog
procedure, and then unloads the form.
6-33
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
With cmbCause
.AddItem ("Scheduled Maintenance")
.AddItem ("Just plain wore out")
.AddItem ("Jammed up")
.AddItem ("Gummed up")
.AddItem ("Screwed up")
.AddItem ("Other")
End With
End Sub
This code is called when the form is initialized. It adds a text string into the Name
field, and it fills the Combo Box with descriptions for the equipment failure.
6-34
*()DQXF
ZZZML\LWHFKFRP
Student Guide
3. Copy the code from this text file and paste it into the form code module.
4. From the Debug menu, select Compile.
This will check the code modules for errors.
6-35
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
6-36
*()DQXF
ZZZML\LWHFKFRP
Student Guide
3. Within each procedure, add a line of code to open the form you just created. For
example, the code for the CmdMixMaintNow button will resemble the following:
Private Sub CmdMixMaintNow_Click()
CloseDigitalPoint "fix32.node8.mixmaint.F_CV"
frmMaintLog.Show
End Sub
6. Click the buttons in the picture to force the equipment to go into maintenance mode.
Fill out the form and experiment with the Cancel and Send buttons.
7. When finished, return to Configure mode and Close the MaintOverview picture.
6-37
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
1. Lets say you have a detailed form for entering process data into Excel. Is it possible to
copy or export the form from Excel and paste or import it into iFIX? Is it possible to take
an iFIX form and bring it into Excel?
2. When working with a picture, we have 12 events we can use to activate code. How many
events does a form have? List those events that a form has but a picture does not.
3. By now you have discovered that single threaded VBA will not process scripts while a
message box is opened. Will VBA be processed if a form is opened?
4. With iFIX, there are two ways to present a pop-up window that displays mostly text data
and/or solicits operator input. You could build a small picture (*.GRF) that contains your
information, or you could build a form. Discuss the pros / cons of each approach.
5. We saw that it is possible use Globals \ User as a place to store global objects, and global
subroutines and functions. Is it possible to use Globals \ User to store global forms? If
so, what code would you have to write to open one of these forms?
6-38
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Chapter 7
Controlling VBA Code
7-1
*()DQXF
7.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Section Objectives
This section provides information on decision making in VBA programs. The student will work
with different ways to make decisions in the VBA code and the impact of Looping. This
includes the following:
Decision Statements
Looping
Do Loops
DoEvents
7-2
*()DQXF
ZZZML\LWHFKFRP
Student Guide
7-3
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
B. ELSE statement
7-4
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Else
7-5
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
define message
define buttons
define title
display message
MyString = Yes
Else
user chose no
MyString = No
7-6
*()DQXF
ZZZML\LWHFKFRP
Student Guide
7-7
*()DQXF
7.1.2.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
A. Using ElseIf
Many ElseIf clauses can be used in a block If, but none can appear after an Else
clause
If none of the ElseIf conditions are True (or if there are no ElseIf clauses), the
statements following Else are executed
After executing the statements following Then or Else, execution continues with
the statement following End If
7-8
*()DQXF
ZZZML\LWHFKFRP
Student Guide
If condition Then
[statements]
[ElseIf condition-n Then
[elseifstatements] ...
[Else
[elsestatements]]
End If
7-9
*()DQXF
7.1.3.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Although not required, it is a good idea to have a Case Else statement in your
Select Case block to handle unforeseen testexpression values
Each nested Select Case statement must have a matching End Select
statement
7-10
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Dim intValveNum
Case 6, 7, 8
7-11
*()DQXF
7.1.4.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
GoTo _________________________________________________
A. Notes
The required line argument can be any line label or line number
GoTo can branch only to lines within the procedure where it appears
B. Style
Too many GoTo statements can make code difficult to read and debug
-
Line2:
MyString = "Number equals 2"
LastLine:
Debug.Print MyString
End Sub
7-12
*()DQXF
ZZZML\LWHFKFRP
Student Guide
7.2. Looping_________________________________________________
A. Looping will allow for more efficient non repetitive VBA coding
Do Loop
Check condition
at the top of the
loop
Check condition
at the bottom of
the loop
(always executes
the loop at least
once)
Do Until <condition>
Do While <condition>
<statements>
<statements>
Loop
Loop
Do
Do
<statements>
Loop Until <condition>
<statements>
Loop While <condition>
7-13
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
A. Do Loops are typically executed when a condition is true or until it becomes true
Do While Loop
Do Until Loop
B. Do While Loop
Response = vbYes
Loop
7-14
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Do
Response = MsgBox (Msg, Style, Title, Help, Context)
Loop Until Response = vbNo
7-15
*()DQXF
7.2.2.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Use if you know the exact amount of times a group of statements need repeating
-
Step
Statements
-
the group of code statements executed each pass through the loop
Next
-
Next used with counter name defines the end of the loop
the counter name in the Next statement is optional, but can make the code
more readable
C. Additional Notes
Changing the value of counter while inside a loop can make it difficult to read and
debug the code
Any number of Exit For statements may be placed anywhere in the loop as an
alternate way to exit
For...Next loops can be nested by placing one For...Next loop within another
-
7-16
*()DQXF
ZZZML\LWHFKFRP
Student Guide
For i = 0 To 4
Response =
Next i
End Sub
7-17
*()DQXF
7.3.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
DoEvents _______________________________________________
A. Understanding DoEvents
B. Additional Notes
7-18
*()DQXF
7.3.
ZZZML\LWHFKFRP
Student Guide
DoEvents _______________________________________________
For counter = 1 To 10
'display the counter message
Application.StatusBar = "Counter Value: " & counter
txtcount.Caption = "Counter Value: " & counter
Application.StatusBar = False
End Sub
starttime = Timer
Do While Timer - starttime < delay
DoEvents
Loop
End Sub
7-19
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
One of the most common uses for layering is in conjunction with large displays
Further, layers are an effective security feature in that you can turn off a specific
layer so that certain objects cannot be viewed by one or a set of operators
B. Setting Layers
Establish layering using the Set Layer and Display Layers buttons in the
WorkSpace
Displaying layers applies to the entire picture and determines what layers
are displayed in the picture
2. Click the Set Layer button on the Tools toolbar or the Toolbox
-
3. Click the button that represents the number of the layer to be assigned
-
To assign multiple layers, select the Allow for Multiple Layers check
box and then click the numbered buttons, or click Select All
4. Click OK
D. To display layers in a picture
1. Click the Display Layers button on the Tools toolbar or the Toolbox
-
If a mistake is made, click Deselect All Layers and repeat this step
3. Click OK
7-20
*()DQXF
ZZZML\LWHFKFRP
Student Guide
7-21
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Example
-
Example
-
If layer 8 and layer 3 are being displayed, then bit #7 and bit #2 will be set
Special case:
-
DisplayLayer = -1
7-22
*()DQXF
ZZZML\LWHFKFRP
Student Guide
7-23
*()DQXF
7.5.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Decision Statements
Lab Exercise 7
7-24
*()DQXF
ZZZML\LWHFKFRP
Student Guide
When you are finished with this lab, turn to page 7-35 and answer the Summary Questions.
Resources:
The iFIX On-line Help and E-Books
The iFIX Automation On-line Help
Microsoft Visual Basic On-line Help
Lab Information
You will create a form to allow you to display any combination of sets of objects. This is
done using layers. We will guide you through information that talks about layers.
7-25
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
7-26
*()DQXF
ZZZML\LWHFKFRP
Student Guide
7-27
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
4. Add the following Controls to the to the form. Use the names provided below.
Control
Name
Caption
Layer
Displayed
Check Box
chkTanks
Tanks
Check Box
chkTempGauges
Temperature Gauges
Check Box
chkPackStat
Packaging Station
Check Box
chkPallStat
Palletizer Station
Command Button
cmdClear
Clear
N/A
Command Button
cmdReset
Reset
N/A
Command Button
cmdFinished
Finished
N/A
Label
lblCurPic
Current Picture:
N/A
Text Box
txtCurPic
7-28
N/A
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Below is a table listing some of the procedures needed to complete this exercise:
Procedure
Name
Procedure
Type
Purpose
Approximate
Lines of Code
cmdClear_Click()
Sub Procedure
cmdReset_Click()
Sub Procedure
cmdFinished_Click()
Sub Procedure
Sub Procedure
6 to 8
UserForm_Initialize()
Sub Procedure
Sub Procedure
chkPackStat_Click()
Sub Procedure
chkPallStat_Click()
Sub Procedure
AdjustLayer()
Sub Procedure
8 to 10
DispLayerBitStat()
Function
Determine if a particular
layer is currently being
displayed
8 to 10
chkTank_Click()
chkTempGauges_Click()
Note: These names are just a guideline. Feel free to use whatever functions you feel
will get the job done!
7-29
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
1. AdjustLayer Enter the following sub procedure into the form code module for the
frmPickLayer form:
Else
End If
Application.ActiveDocument.Page.DisplayLayer = crntDisplay
End Sub
This sub procedure needs to set bits in the DisplayLayers property of the picture.
The LayerArg is the layer of the object (1 to 30), and CheckBoxArg is a true of false.
We use OR and XOR to clear and set bits in the DisplayLayers property. Remember
that the DisplayLayers value is essentially a bit pattern.
2. cmdFinsihed_Click() Create the code to hide the form when the Finished button is
clicked. This can be done with one line of code!
7-30
*()DQXF
ZZZML\LWHFKFRP
Student Guide
3. cmdReset_Click() This procedure will set all the checkboxes to true. That is, it
sets the four layers to be visible. This function can be written with 5 lines of code.
4. cmdClear_Click() This procedure will set all the checkboxes to false. That is, it
sets the four layers to be not visible. This function can be written with 5 lines of
code.
5. DispLayerBitStat - This function is used to test a layer to see if it is currently
displayed. The function could use the AND operator to test your bit value. For
example if our bit pattern is 00110, and we want to see if the third bit is set, we could
take 00110 AND 00100 = 00100. So if we AND two values and we get a non-zero
value, we know the bit we are interested in is set.
LayerBeingTested = 2 ^ (TestBit - 1)
testLayer = DispLayerValue And LayerBeingTested
If testLayer = 0 Then
DispLayerBitStat = False
Else
DispLayerBitStat = True
End If
End Function
7-31
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
6. chkTank_Click() For every checkbox on the form, there is a click event. Use the
following code below as a hint to creating this procedure.
Now, repeat this code for the other three Check Boxes.
7. UserForm_Initialize - You will want to initialize your form when you open it so that
it accurately shows which layers are currently being displayed. You will have to
check each bit of the DisplayLayer property value, and if the bit is set, then you will
have to set the checkbox Value property to true.
Dont forget our special case, -1, which should set all your checkbox values to true.
Consider the code fragment below as you choose your strategy for writing this code.
txtCurPic.Value = Application.ActiveDocument.Name
With Application.ActiveDocument.Page
'
'
'
'
chkTanks.Value = DispLayerBitStat(.DisplayLayer, 1)
chkTempGauges.Value = DispLayerBitStat(.DisplayLayer, 6)
chkPackStat.Value = DispLayerBitStat(.DisplayLayer, 8)
chkPallStat.Value = DispLayerBitStat(.DisplayLayer, 9)
End With
7-32
*()DQXF
ZZZML\LWHFKFRP
Student Guide
End If
Exit Sub
ErrorHandler:
7-33
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
1
2
3
4
5
6
7
8
9
10
11
12
13
7-34
*()DQXF
ZZZML\LWHFKFRP
Student Guide
1. Compare using Else, If (two separate lines of code) versus ElseIf versus Case.
When does it make sense to use each?
2. When working with the For loop, the typical construct is For X = 1 to 4321. What is the
construct when you have a finite number of objects, but you dont know how many?
3. Is it legal to write a Do Loop that has no condition statements, neither at the beginning,
nor the end? If so, how do you exit such a loop?
4. What are the consequences of working with our Loops in our current, single-threaded
implementation of VBA? How does Do Events fit into this picture?
5. If you wanted to test a value every 5 seconds, you could use a loop. Alternatively, how
could you use a block in the FIX database to trigger an event every 5 seconds? What
object(s) in iFIX could be used?
7-35
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
7-36
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Chapter 8
Collections and Groups
8-1
*()DQXF
8.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Section Objectives
This section provides will discuss differences between collections and groups. The students will
isolate and manipulate properties of objects existing in a collection and a group. Also, user
defined collections will be discussed. This includes the following:
Grouped Objects
VBA Collections
The student will create logical expressions to affect the behavior of grouped objects.
8-2
*()DQXF
ZZZML\LWHFKFRP
Student Guide
The Group object holds information describing a number of objects used as a unit
-
Example: Two rectangles and two circles can be grouped to for a pump
Group objects together so that they function as a unit allowing for the
manipulation of all objects in the group as a unit instead of individually
Grouping objects in the iFIX WorkSpace adds objects to a new group type object
called FIX2DGroup
-
This new FIX2DGroup object has its own name, properties, methods and
events
8-3
*()DQXF
8.1.1.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
A. ContainedObjects Property
Syntax - Group.ContainedObjects
-
8-4
*()DQXF
8.1.1.
ZZZML\LWHFKFRP
Student Guide
8-5
*()DQXF
8.1.2.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
A. ContainedSelections Property
Syntax - Group.ContainedSelections
-
Major use of this group property is at design time using custom tools
8-6
*()DQXF
8.1.2.
ZZZML\LWHFKFRP
Student Guide
8-7
*()DQXF
8.1.3.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Group Object contains user defined objects representing controls, elements, and
physical items
8-8
*()DQXF
8.1.3.
ZZZML\LWHFKFRP
Student Guide
8-9
*()DQXF
8.1.4.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Group Events__________________________________________
Multiple nested objects can have the same event, since only one is selected
8-10
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Many times similar objects are actually part of a group or collection of objects
Collection itself is defined as an object and has properties, methods and events
-
B. Collection Types
Pre-defined Collections
-
8-11
*()DQXF
8.2.1.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
A. Examples
In Excel, the Workbooks collection is the set of all open Workbook objects
In Excel, the Worksheets collection is the set of all open Worksheet objects in a
workbook
Pictures
Schedules
Dynamo Sets
Many application objects can not be referred to by simply using the object name
-
Example:
-
when referring properties of the current picture, you use the following
syntax:
Application.ActiveDocument
Application.ActiveDocument.Name
Application.ActiveDocument.Path
8-12
*()DQXF
8.2.1.
ZZZML\LWHFKFRP
Student Guide
8-13
*()DQXF
8.2.2.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
A. Notes
The items, or members, in a collection need only be related by the fact that
they exist in the collection
B. Creating a Collection
A collection can be created the same way other objects are created
-
For example:
Dim X As New Collection
The entire collection can be iterated using the For Each...Next statement
Once a collection is created, members can be added using the Add method and
removed using the Remove method
Specific members can be returned from the collection using the Item method
8-14
*()DQXF
8.2.2.
ZZZML\LWHFKFRP
Student Guide
check the name of each object and display the name in MsgBox
MsgBox truckobj.Name
Next
End Sub
8-15
*()DQXF
8.2.2.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
C. Add Method
Syntax
object.Add item, key, before, after
-
object Required
item Required
key Optional
before Optional
after Optional
Additional Notes
-
An error also occurs if a specified key duplicates the key for an existing
member of the collection
8-16
*()DQXF
8.2.2.
ZZZML\LWHFKFRP
Student Guide
D. Remove Method
Syntax
object.Remove index
-
object Required
index Required
If the value provided as index doesnt match an existing member of the collection,
an error occurs
E. Count Property
Example:
-
This example uses the Collection object's Count property to specify how
many iterations are required to remove all the elements of the collection
Next
' begin at 1.
8-17
*()DQXF
8.2.2.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
D. Item Method
Syntax
object.Item(index)
object Required
index Required
Print MyCollection.Item(1)
8-18
*()DQXF
8.2.3.
ZZZML\LWHFKFRP
Student Guide
MsgBox grpobj.Name
Next grpobj
End Sub
mytruck.Add Rect1
mytruck.Add Oval1
mytruck.Add Oval2
mytruck.Add RoundRect1
check the name of each object and displa y the name in MsgBox
For Each truckobj In mytruck
MsgBox truckobj.Name
End Sub
8-19
*()DQXF
8.3.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
8-20
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Use decision statements to evaluate the objects name and set the layer
When you are finished with this lab, turn to page 8-33 and answer the Summary Questions.
Resources:
The iFIX On-line Help and E-Books
The iFIX Automation On-line Help
Microsoft Visual Basic On-line Help
Lab Information
You will work with an existing picture called CIP Overview that has many objects. Your
code will loop through all the objects, check the name property and set the layer based on the
name property. You will copy and modify the form you created in an earlier exercise to
select which layers you want to view during run-time.
8-21
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
This picture is a CIP (Clean in Place) Overview that displays many different pieces of
information:
2. Go to the Visual Basic Editor where you will write the code that will loop through
all the objects in the picture.
8-22
*()DQXF
ZZZML\LWHFKFRP
Student Guide
This procedure will be used to loop through each object in the picture using a For
Each loop.
5. Open the Immediate Window to view the results of the For Each loop.
8-23
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
6. Run the code by placing the cursor on ChangeLayerAssignments and pressing <F5>
The screen should resemble the following:
This code works, but it only counts the top level objects in the picture. If we have a
group object, like Group1 that is made up of rect1, oval1, and line1, this procedure
will count Group1, but it will miss the objects contained in the Group.
7. Modify the code to include the following statement just before the Next statement:
If MyObj.ClassName = "Group" Then Call DrillObj(MyObj , 1)
8-24
*()DQXF
ZZZML\LWHFKFRP
Student Guide
8. The following code can be used to drill down into group objects. Enter this new
sub procedure into the same module:
'This sub procedure drills down into a gr oup object and shows
'all the objects that make up the group object.
Private Sub DrillObj(ObjArg As Object, DrillLevelArg As Long)
'This constant allows us to indent our output based on
'how deep we are inside a grouped object.
Const IndentStr As String = "********************"
Dim GrpObj As Object
ObjTotal = ObjTotal + 1
With GrpObj
End With
Next
End Sub
8-25
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
9. With the new DrillObj sub procedure in place, run the code again by placing your
cursor on ChangeLayerAssignments and pressing <F5>.
Now the script works all objects were displayed in the immediate window.
8-26
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Bit
Layer
Name fragment
16
32
64
128
256
10
512
10
11
1024
11
12
2048
12
13
4096
13
14
8192
8-27
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
For example, if you want to set all headers to the third layer, you can write a script
similar to the following:
If Left(MyObj.Name, 4) = "Pipe" Or _
Left(MyObj.Name, 3) = "Hdr" Or _
Left(MyObj.Name, 5) = "CipHd" Then
'Increment "Pipe and Header" counter
TotlPipeInt = TotlPipeInt + 1
'set the object's layer to 4, which is the third layer
MyObj.Layer = 4
End if
2. Now, it is your job to write the code to take all the objects in the four layers of the
picture and assign them to the appropriate layer. Start with the Tanks first.
Hints:
(a)
(b)
You will need to declare an integer variable to track the number of tank
objects (for example: TotlTankInt)
(c)
You will need to use the Layer Value (from the table above) in the program
to set the objects layer.
3. Test the code by running it from the VBE, and then checking the Layer property of
the tanks in the CIPOVER picture or use the Set Layer tool to see the results.
8-28
*()DQXF
ZZZML\LWHFKFRP
Student Guide
8-29
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
With MyObj
ObjNameStr = .Name
ObjLayerLng = .Layer
ObjClassStr = .ClassName
ObjDescStr = .Description
End With
8-30
*()DQXF
ZZZML\LWHFKFRP
Student Guide
2. You can make your code run faster by minimizing the number of times you call
functions. For example, each time you test an objects name, you call the Left()
function to determine the objects name (tank, pipe, pmp, vlv, etc.).
Instead of calling the function many times in a procedure, you can use the following
code example and use a variable instead.
ObjNameLen = Len(ObjNameStr)
If ObjNameLen > 7 Then
ObjN5cPrefixStr = Left(ObjNameStr, 5)
ObjN4cPrefixStr = Left(ObjNameStr, 4)
ObjN3cPrefixStr = Left(ObjNameStr, 3)
ObjN3cSuffixStr = Right(ObjNameStr, 3)
End If
8-31
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
4. Try the code again with the new changes and see if it works.
Note: The layers for Tanks are already set to Layer 1, so you will need to manually
change a few tanks to a different layer before running the procedure.
8-32
*()DQXF
ZZZML\LWHFKFRP
Student Guide
1. VBAs generic Collection object has only one property. What is it?
2. When working with arrays, if you want to extract the value of one of the elements in the
array, you specify which element you desire by the index. What are the two ways in
which you can access the individual objects in a collection object? Which method is
more reliable?
3. If you want to change the value of an element in an array, you simply use an assignment
statement such as SportsCarCostArray(7) = $60,000, assuming Sportscar is an array. If
you want to substitute one object with another object in a collection, will a statement like
SportsCarCollection(7) = Ferrari?
4. When working with collections, if you want to insert objects into the collection in a
specific place by using statement such as SportsCarCollection.Add Porche, after
Delorian. How would you insert a value into an array?
5. In VBA we can store a set (a group) of items two ways. One way is with an array, the
other way is with a collection. When does it make more sense to use an array and when
does it make more sense to use a collection?
8-33
*()DQXF
8.4.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
8-34
*()DQXF
ZZZML\LWHFKFRP
Student Guide
9. Embedded Objects__________________________________________
Chapter 9
Embedded Objects
9-1
*()DQXF
9.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Section Objectives
This section provides an introduction objects that can be embedded into the WorkSpace.
Specifically, this section explores the following:
Timer Objects
Event Objects
9-2
*()DQXF
9.
ZZZML\LWHFKFRP
Student Guide
Things that happen under software control such a timer being done or an
event trigger based on a PDB value
Object Events
Screen Events
Key Events
Mouse Events
Activated Event
De-Activated Event
9-3
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Variable objects are another type of object that can be added to the iFIX project
think of these variable like any other WorkSpace object (rectangle, oval,
etc.)
Boolean
Byte
Short
Long
Float
Double
String
Acts as a handle to access data from the databases, pictures, and external sources
C. Data variable can then be monitored by other objects such as Event Objects
9-4
*()DQXF
ZZZML\LWHFKFRP
Student Guide
9-5
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
9-6
*()DQXF
ZZZML\LWHFKFRP
Student Guide
These events are valid for both Local and Global variables
9-7
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Class - FixTimer
9-8
*()DQXF
ZZZML\LWHFKFRP
Student Guide
9-9
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
OnTimeOut
Occurs when the time parameters in the Timer Object are true
This event is valid for both picture and schedule Timer Object
9-10
*()DQXF
ZZZML\LWHFKFRP
Student Guide
9-11
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Sources are data from the databases, pictures, and external sources
The container keeps track of data state and performs the event call
Class - FixEvent
9-12
*()DQXF
ZZZML\LWHFKFRP
Student Guide
9-13
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
DataChange
OnTrue
WhileFalse
WhileTrue
OnFalse
These events are valid for both picture and schedule events
9-14
*()DQXF
ZZZML\LWHFKFRP
Student Guide
9-15
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
B. Schedule Object
Schedule Events
-
Events and scripts are asynchronous to the picture code if the schedule is running
as a background task
9-16
*()DQXF
ZZZML\LWHFKFRP
Student Guide
9-17
*()DQXF
9.5.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Embedded Objects
Lab Exercise 9
9-18
*()DQXF
ZZZML\LWHFKFRP
Student Guide
When you are finished with this lab, turn to page 9-24 and answer the Summary Questions.
Resources:
The iFIX On-line Help and E-Books
The iFIX Automation On-line Help
Microsoft Visual Basic On-line Help
Lab Information
You will work with an existing picture that displays equipment maintenance information.
When a piece of equipment goes into maintenance mode, a dialog box will appear prompting
for some maintenance information. You will need to create code so that when the form
appears, the equipment in question appears as the default on the form.
9-19
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
9-20
*()DQXF
ZZZML\LWHFKFRP
Student Guide
2. Add a new Event Object to the picture. Use the following dialog box as an example:
With frmMaintLog
.optReclaim.SetFocus
.optReclaim = True
.optPump.SetFocus
.optPump = True
End With
CmdRclMaintNow.ForeColor = VBRed
End Sub
This procedure is executed when the object (RclPmpMaintEvt) becomes true. This
refers to when the pump enters into maintenance mode. When this happens, the
command button text color turns red notifying the user to click the button to opening
the log maintenance form. Once opened the form will automatically contain
information based on a maintenance event for the reclaim tank
The form, which is one used in an earlier exercise, looks like the following:
9-21
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
4. Notice the following, and recall the code from the previous page:
a. In the Tank section, the Reclaim tank radio button is enabled
.optReclaim = True
.optReclaim = True
b. In the Equipment section, the Pump is radio button is enabled and it is the
currently selected object
.optPump = True
.optPump.SetFocus
c. the Send button is grayed out (because the rest of the dialog box is not filled in)
5. Fill out the rest of the dialog box and click Send.
6. Note that the button Text should return to normal black color once the user has sent
the information. Write the code that will accomplish this task.
7. A new dialog box appears with information about the selections you made.
8. Click OK to return to the picture.
9-22
*()DQXF
ZZZML\LWHFKFRP
Student Guide
1. You will first need to add Event Objects into the picture. Each object is looking for
the equipment to go into maintenance mode. Again, use the Reclaim Tank as a
model.
2. The next thing you need to do is edit the script for each event object. When the
event goes true, the maintenance form will open. You need to write the code for this.
Use the code for the Reclaim Tank as a model.
3. Finally, test the scripts. There are data links in the picture to force the equipment
into maintenance mode. Each time this happens, the form should open prompting
you to enter in the maintenance information.
9-23
*()DQXF
9.6.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
3. When doing a Find and Replace in the exercise, why was it important to select the
Include Scripts check box?
5. What was the purpose of the Event Objects that were used in the exercise?
9-24
*()DQXF
10.
ZZZML\LWHFKFRP
Student Guide
Chapter 10
iFIX Automation
10-1
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
iFIX Automation
iFIX Objects
iFIX Subroutines
EDA Functions
10-2
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Includes references to all the iFIX objects and their corresponding properties,
methods and events plus pre-built subroutines and database functions
10-3
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Figure 10-2 contains the iFIX objects that are available within VBA
C. Additional Notes
Each iFIX object type has its own properties, methods, and events
-
This is why the iFIX Automation Reference help is important to identify the
available functionality for each object
10-4
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Alarm Summary
Application
Arc
Bitmap
Chart
Chord
Color Button
ControlContainer
DataItem
DataItems
DataLink
DataServer
DataServers
Document
Documents
DynamoSet
Event
ExpressionEditor
FindReplace
FixDataSystem
FixFloatPoint
Format
Group
Group (DataSystem)
Groups
Legend
Line
Lines
Linear
Lookup
Oval
Picture
Pen
Pie
Polygon
Polyline
Procedures
Rectangle
RoundRectangle
Scheduler
ScriptLine
ScriptProcedure
ScriptSource
Sources
System
Text
TimeAxis
Timer
UserGlobals
ValueAxis
Variable
Window
Figure 10-2: iFIX Objects
10-5
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Subroutines to allow such actions as reading and writing to the process database
And more
-
10-6
*()DQXF
ZZZML\LWHFKFRP
Student Guide
AcknowledgeAllAlarms
LogIn
AcknowledgeAnAlarm
OffScan
CloseDigitalPoint
OnScan
ClosePicture
OpenDigitalPoint
DisableAlarm
OpenPicture
EnableAlarm
PictureAlias
FetchLimits
PrintReport
FindDataSource
QuickAdd
FindLocalObject
RampValue
GetAllConnections
ReadValue
GetDecimalSeparator
RegCloseKey
GetFormDynamoColor
RegOpenKeyEx
GetFormNumeric
ReplacePicture
GetFormPushbutton
GetFormRamp
SetAuto
SetManual
GetFormSlider
GetLocaleInfoA
ShellExecute
ToggleDigitalPoint
GetUserDefaultLCID
ToggleManual
HandleError
ToggleScan
IsUserFxg
WriteValue
LocateObject
Figure 10-3: iFIX Subroutines
10-7
*()DQXF
10.4.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Subroutines will allow such actions as reading and writing to the process database
blocks, working with block alarms and manipulating the mode of database blocks
Note that when referring to a specific node, tag, field combination the VBA
subroutines syntax can be formatted in multiple ways
FetchLimits returns the High and Low EGUs of the specified data source
-
lValue = ReadValue("AI1")
ReadValue reads the value of the specified block storing the result in a variable
-
OpenDigitalPoint "DO1"
ToggleDigitalPoint "DO1"
WriteValue sets the value of the current value of the specified database block
-
WriteValue 1, "DO1"
10-8
*()DQXF
ZZZML\LWHFKFRP
Student Guide
DisableAlarm "AI1"
EnableAlarm "AI1"
OnScan "AI1"
OffScan "AI1"
SetAuto "AI1"
SetManual "AI1"
ToggleManual "AI1"
ToggleScan "AI1"
QuickAdd launches the Quick Add dialog box for adding a data block
-
iStatus = QuickAdd("NewBlock1")
10-9
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Used for retrieving the process database tag name used in the animation operation
FIX32.Node.Tag.Field
End Sub
10-10
*()DQXF
ZZZML\LWHFKFRP
Student Guide
10-11
*()DQXF
10.5.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
A. Notes
Syntax
Shell(pathname[,windowstyle])
-
pathname Required
Variant (String)
windowstyle Optional
B. Additional Notes
If the Shell function successfully executes the named file, it returns the task ID of
the started program
-
If the Shell function can't start the named program, an error occurs
This means that a program started with Shell might not finish executing
before the statements following the Shell function are executed
10-12
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Constant
Value
Description
vbHide
vbNormalFocus
vbMinimizedFocus
vbMaximizedFocus
vbNormalNoFocus
vbMinimizedNoFocus
10-13
*()DQXF
10.6.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
A. The following list contains the iFIX Database Functions that are available
The functions allow access and manipulation of the process database using the
Easy Data Access layer of the iFIX architecture
eda_add_block
-
eda_delete_block
-
eda_type_to_index
Retrieves the type index for the specified string containing a block type
FixGetMyName
-
eda_save_database
-
eda_reload_database
-
eda_get_pdb_name
-
Get the node name of this node whether or not the FIX is running
NlsGetText
Translates an error number returned as a string.
10-14
*()DQXF
ZZZML\LWHFKFRP
Student Guide
10-15
*()DQXF
10.7.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
10-16
*()DQXF
ZZZML\LWHFKFRP
Student Guide
When you are finished with this lab, turn to page 10-26 and answer the Summary Questions.
Resources:
Lab Information
You will work with an existing picture and form. The form displays status information on
any object in a picture that has the selectable property set to true. The form has five tabs.
The tab names are Status, Control, Alarms, Chain, and Tools. Clicking on any of the tabs
(except Tools) calls a subroutine specific to that tab.
You will be working with the Control, Alarms, and Tools tabs adding additional code to the
form. There will be no need to add any additional controls to the form. All the form
development except the new code to add has been done.
Basically the form is called up, the user selects a Data Link object then clicks on the Status
tab of the form. Information about the database block is filled in the form.
10-17
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
10-18
*()DQXF
ZZZML\LWHFKFRP
Student Guide
10-19
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
10-20
*()DQXF
ZZZML\LWHFKFRP
Student Guide
3. Go to the subroutine named TagStatus. Add the following four lines of code needed
to trim off the field
To do this we look for a specific character, the period. The InStr function searches
the variable tagsource for the first period starting from the left. The characters are
counted and stored in the variable tagTrim. We then use the InStr function to go the
number of characters in TagTrim + 1 then to the next period. This repeats again until
we are at the last period before the Field. Since we now know the number of
characters to get just the Server.Node.Tag we then use the Left$ function to get the
correct characters from tagsource.
Now anytime TagStatus is called the tagsource will be trimmed. This means any time
you want to update the source, call TagStatus.
10-21
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
10-22
*()DQXF
ZZZML\LWHFKFRP
Student Guide
1. The Status tab is now complete. Clicking on the Status tab calls the subroutine
TagStatus.
TagStatus reads in a variety of fields using the ReadValue subroutine with the
tagsource variable. One of the fields TagStatus reads in is the block name. The
statement looks like this tagName = readvalue(tagsource & "A_TAG")
2. Since we already have the block name in the variable called tagName we can build
the toggle subroutines using tagName variable as the source to toggle.
3. Again, open form in the VBE. Click on the Control tab. Select one of the
pushbuttons and Edit Script writing the following code appropriately. Note that
TagControl subroutine is called. This refreshes the data since it will have changed.
TagControl
End Sub
10-23
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Hint: Update Alarm Extensions button should capture the data in the text boxes and
send it to the proper fields using the WriteValue sub routine.
10-24
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Hint: QuickAdd requires a block name. Since it cannot be hard coded use the
InputBox as a method of supplying a name.
Hint: Create a variable called NewBlockName and populate this variable with user
input from the InputBox function. Use the iFIX Automation Interface help for usage.
10-25
*()DQXF
10.8.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
1. Whats the advantage of using ReadValue and WriteValue as opposed to reading and
writing the values directly?
4. What is the purpose of the Alarm Extension fields? How can you use them with VBA?
10-26
*()DQXF
11.
ZZZML\LWHFKFRP
Student Guide
Chapter 11
Error Handlers
11-1
*()DQXF
11.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Section Objectives
This section provides information on dealing with error handlers. This includes the following:
This chapter also contains a list of all the VBA error codes.
11-2
*()DQXF
11.1.
ZZZML\LWHFKFRP
Student Guide
11-3
*()DQXF
11.1.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
11-4
*()DQXF
11.1.
ZZZML\LWHFKFRP
Student Guide
VBA searches for any active error handlers if none are found VBA handles it
Allowing VBA to handle errors sometimes is ok but often can cause issues
-
Nothing happens
Any error messages that VBA creates may not provide good information
11-5
*()DQXF
11.2.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
This method finds any error that occurs during run time
Another way is to simply use logic to check for error conditions within the code
-
This method only finds the errors that are specifically checked for during
execution
Only provides error handling for errors that meet specific criteria
11-6
*()DQXF
11.2.
ZZZML\LWHFKFRP
Student Guide
End If
End Sub
11-7
*()DQXF
11.3.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Decide what information the user needs about the error or resolving the error
Important Note:
-
This will stop the script and hang up the Scheduler thread
Check for error condition anytime during the running of the procedure
Information about the VBA errors can be retrieved from the Err object
The three Err Object properties used the most are as follows:
Err.Source returns the name of the project in which the error occurred
11-8
*()DQXF
11.3.
ZZZML\LWHFKFRP
Student Guide
y As Integer,
z As Integer,
msg As String
Exit Sub
MyHandler:
' Display the error message
End Sub
11-9
*()DQXF
11.3.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Use Resume statement to return to line of code which caused the error
Use Resume Next statement to go to the next statement after the one
which caused the error
DivByZeroHandler:
Case 11
Resume GetDivisorOnly
Case 6
' Overflow
Resume GetDividendAndDivisor
Case 13
Exit Sub
End Select
11-10
*()DQXF
11.3.
ZZZML\LWHFKFRP
Student Guide
UserInput:
entry = InputBox("Enter Value to be added")
If entry = "" Then
End If
InputErrHandler:
Resume Next 'if error go to next statement after error
End Sub
11-11
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
recall that MsgBox or other user interface code should NOT be used in an
Error Handler for a script running in a background schedule
11-12
*()DQXF
ZZZML\LWHFKFRP
Student Guide
MyErrHandler:
" & _
"Error number:
Resume Next
End Sub
11-13
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
ErrorHandler is the label that the code will jump to when an error occurs
-
The error handling code would be placed after the label ErrorHandler:
-
11-14
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Exit Sub
ErrorHandler:
HandleError
End Sub
11-15
*()DQXF
11.4.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
A. Error Codes
Some trappable errors can also occur during development or compile time
Test and respond to trappable errors using the On Error statement and the Err
object
Unused error numbers in the range 1 1000 are reserved for future use
11-16
*()DQXF
11.4.
ZZZML\LWHFKFRP
Student Guide
Code
3
5
6
7
9
10
11
13
14
16
17
18
20
28
35
47
48
49
51
52
53
54
55
57
58
59
61
62
63
67
68
Message
Return without GoSub
Invalid procedure call
Overflow
Out of memory
Subscript out of range
This array is fixed or temporarily locked
Division by zero
Type mismatch
Out of string space
Expression too complex
Can't perform requested operation
User interrupt occurred
Resume without error
Out of stack space
Sub, Function, or Property not defined
Too many DLL application clients
Error in loading DLL
Bad DLL calling convention
Internal error
Bad file name or number
File not found
Bad file mode
File already open
Device I/O error
File already exists
Bad record length
Disk full
Input past end of file
Bad record number
Too many files
Device unavailable
11-17
*()DQXF
11.4.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Code
70
71
74
75
76
91
92
93
94
97
298
320
321
322
325
327
328
335
336
337
338
360
361
363
364
365
368
371
380
381
Message
Permission denied
Disk not ready
Can't rename with different drive
Path/File access error
Path not found
Object variable or With block variable not set
For loop not initialized
Invalid pattern string
Invalid use of Null
Can't call Friend procedure on an object that is not an instance of the
defining class
System DLL could not be loaded
Can't use character device names in specified file names
Invalid file format
Cant create necessary temporary file
Invalid format in resource file
Data value named not found
Illegal parameter; can't write arrays
Could not access system registry
ActiveX component not correctly registered
ActiveX component not found
ActiveX component did not run correctly
Object already loaded
Can't load or unload this object
ActiveX control specified not found
Object was unloaded
Unable to unload within this context
The specified file is out of date. This program requires a later version
The specified object can't be used as an owner form for Show
Invalid property value
Invalid property-array index
11-18
*()DQXF
11.4.
ZZZML\LWHFKFRP
Student Guide
Code
382
383
385
387
393
394
400
402
419
422
423
424
425
429
430
432
438
440
442
443
445
446
447
448
449
450
451
452
453
454
Message
Property Set can't be executed at run time
Property Set can't be used with a read-only property
Need property-array index
Property Set not permitted
Property Get can't be executed at run time
Property Get can't be executed on write-only property
Form already displayed; can't show modally
Code must close topmost modal form first
Permission to use object denied
Property not found
Property or method not found
Object required
Invalid object use
ActiveX component can't create object or return reference to this object
Class doesn't support Automation
File name or class name not found during Automation operation
Object doesn't support this property or method
Automation error
Connection to type or object library for remote process has been lost
Automation object doesn't have a default value
Object doesn't support this action
Object doesn't support named arguments
Object doesn't support current locale setting
Named argument not found
Argument not optional or invalid property assignment
Wrong number of arguments or invalid property assignment
Object not a collection
Invalid ordinal
Specified DLL function not found
Code resource not found
11-19
*()DQXF
11.4.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Code
455
457
458
459
460
461
480
481
482
483
484
485
486
520
521
735
744
746
31001
31004
31018
31027
31032
31036
31037
Message
Code resource lock error
This key is already associated with an element of this collection
Variable uses a type not supported in Visual Basic
This component doesn't support events
Invalid Clipboard format
Specified format doesn't match format of data
Can't create AutoRedraw image
Invalid picture
Printer error
Printer driver does not support specified property
Problem getting printer information from the system. Make sure the
printer is set up correctly
Invalid picture type
Can't print form image to this type of printer
Can't empty Clipboard
Can't open Clipboard
Can't save file to TEMP directory
Search text not found
Replacements too long
Out of memory
No object
Class is not set
Unable to activate object
Unable to create embedded object
Error saving to file
Error loading from file
11-20
*()DQXF
12.
ZZZML\LWHFKFRP
Student Guide
Automation______________________________________________
Chapter 12
Automation
12-1
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Automation
References
Binding
12-2
*()DQXF
12.1.
ZZZML\LWHFKFRP
Student Guide
Word could allow iFIX VBA script to start Word and append a document
SQL Server could allow another application to build databases and tables
The VBA project needing to connect to another application must have a reference
to that applications object library
-
This enables the ability to create VBA scripts and have helpful
functionality available like Intellisense during development
An instance of the application you want to work with must be loaded into memory
-
12-3
*()DQXF
12.2.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
A. Notes
Before working with another applications objects you must set up a reference to
that applications object library
-
Once a reference is established the objects for that application are available
B. Adding References
C. Additional Notes
The available references are based on the application installation and NT registry
-
MyComputer\HKEY_CLASSES_ROOT\TypeLib\
12-4
*()DQXF
12.2.
ZZZML\LWHFKFRP
Student Guide
12-5
*()DQXF
12.3.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
A. Reference notes
Once the proper library reference is made in a VBA project, the objects for that
reference are available to be used in VBA script
These examples can contain objects but the objects can not be manipulated
by other applications (Automation controllers)
B. Automation notes
The concept of Binding is used to connect the Automation controller and the
Automation server
-
This binding process can take place the first time an object is accessed during
VBA script development or during runtime of the script
12-6
*()DQXF
12.3.
ZZZML\LWHFKFRP
Student Guide
These applications do have their own object library available for clients to access
Examples:
-
Outlook
Internet Explorer
Explorer
ActiveX objects
D. Some applications that allow Automation can be both a Client and Server
These applications also have their own object library reference for clients to
access
Examples:
-
iFIX
Word
Excel
PowerPoint
Access
12-7
*()DQXF
12.4.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Normally binding will be accomplished in the VBA code using both the Dim and
Set statements
The Set statement will load the instance of the application being referenced into
memory
Intellisense is available
It is possible to bind using the Dim statement without the Set but this has other
consequences such as non efficient memory usage
B. There are multiple ways to use the Dim and Set statements
12-8
*()DQXF
12.4.
ZZZML\LWHFKFRP
Student Guide
= CreateObject(Word.Application)
12-9
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
New is used in the Dim statement to create a new instance of the object
-
The new instance of the object is not created until the variable is referred to in a
line of code
-
In Figure 12-5, varname is not actually created until the second line of
code
Can be considered wasteful because it creates it before you use it
12-10
*()DQXF
12.4.2.
ZZZML\LWHFKFRP
Student Guide
A. The Set statement also lets VBA know you want to work with the Automation object
The Set statement creates a new instance as soon as the Set statement is run
Set can also use the keyword New to create a new instance of the object
12-11
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Depending how the new object variable is declared determines if early or late
binding is used
-
VBA will use late binding if the declaration of the variable is as Object
12-12
*()DQXF
ZZZML\LWHFKFRP
Student Guide
GetObject(pathname, class)
-
Pathname can be drive, folder and filename or a file containing the object
you want to work with.
Class specifies the Automation Server application and the type of object to
work with
Application.ObjectType
12-13
*()DQXF
12.5.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Example 1 ____________________________________________
Use the following steps for sending a message using Microsoft Outlook:
-
In the VBE, make sure that in the Tools menu, References item,
"Microsoft Outlook 8.0 Object Library" is checked off
A report with descriptions and values which are built before the
NewMessage.Body statement is executed
This will place the message in the "Outbox" until the next time the messages are
sent
-
12-14
*()DQXF
12.5.
ZZZML\LWHFKFRP
Student Guide
Example 1______________________________________________
Dim ol As Object
Dim NewMessage As Object
Set ol = New
Outlook.Application
NewMessage.Send
End Sub
12-15
*()DQXF
12.6.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Example 2______________________________________________
A. Word example
Notice that at each step, the WorkSpace status bar displays status information
12-16
*()DQXF
12.6.
ZZZML\LWHFKFRP
Student Guide
Example 2______________________________________________
.ActiveDocument.Paragraphs.Add.Range.InsertAfter_
UserForm1.TextBox1.Value
.ActiveDocument.saveas "C:\dynamics\MyNotes.doc"
End With
Set Wordapp = Nothing
Application.StatusBar = ""
End If
End Sub
12-17
*()DQXF
12.7.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Automation
Lab Exercise 12
12-18
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Write code to capture data from an existing source and append it to a document
Use the Object Browser in the VBE to search for advanced features like bold font
and paragraph formatting
When you are finished with this lab, turn to page 12-31 and answer the Summary Questions.
Resources:
Lab Information
The first part of the lab will create the basic functionality of the Automation connection.
The second part of the lab will add advanced features.
12-19
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
2. Switch to Run mode to make sure the functionality of this picture is working.
Particularly the buttons that bring up the Maintenance log form.
3. You can force the equipment into Maintenance mode by clicking the Maint Now
button. This brings up the form frmMaintLog. You will be adding code to this form.
The new code will transfer the information currently viewed in the MsgBox when the
Send button is selected to a Word document.
12-20
*()DQXF
ZZZML\LWHFKFRP
Student Guide
3. Right Mouse Click on the Send button and select View Code
Scrolling through the code you will notice that the code calls a subroutine called
WriteLog. The WriteLog subroutine is where the MsgBox is invoked presenting the
user with the information captured from the form.
What we want to do is call another procedure that you will design that gets called
after MsgBox and appends the Word document.
The name of the new procedure will be AppendWordDoc. Once the code is
complete add the statement AppendWordDoc as the last line in WriteLog.
The coding is going to be done in steps reflecting the goals described at the start of
the lab.
12-21
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
OpenWord:
Set Wordapp = CreateObject("Word.Application")
Resume Next
End Sub
This code declares the variable WordApp, then attempts to set the variable using
the GetObject function. If there is no application to get, an error occurs causing the
error handler OpenWord to be invoked. The error handler loads Word into memory
using the Set statement then Resumes Next which will be the next line of code after
the GetObject statement. You will write that code next.
12-22
*()DQXF
ZZZML\LWHFKFRP
Student Guide
With Wordapp
.Documents.Open ("C:\dynamics\APP\MaintLog.doc")
.ActiveDocument.Paragraphs.Add.Range.InsertAfter Msg3LineStr
OpenWord:
Set Wordapp = CreateObject("Word.Application")
Resume Next
End Sub
The new code opens the document and appends to the document.
12-23
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
3. Make sure the picture is open in Run mode, and test the new code.
a. During development you may have loaded instances of Word into memory and
not have unloaded them. Use task manager to check and remove if needed.
b. Did you add the line of code to the WriteLog procedure to call the
AppendWordDoc procedure?
c. Did you add Word to the list of References in VBA?
12-24
*()DQXF
ZZZML\LWHFKFRP
Student Guide
.ActiveDocument.saveas "C:\dynamics\APP\MaintLog.doc"
.quit
End With
Exit Sub
OpenWord:
12-25
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
The document is hard to read and not easy to distinguish between messages. The new
feature you add will change this.
2. Now you will add code to Bold the text and separate any new Paragraphs
The Object Browser will be used to isolate the methods or properties that can be used
to Bold and format paragraphs.
12-26
*()DQXF
ZZZML\LWHFKFRP
Student Guide
3. This list is somewhat short and it will be left up to you to write the code.
Hint: A new line can be added to invoke each new feature like bolding. The new
statement starts just like the one that appends the document. There is more than one
way to accomplish this. For instance the entire document could be bolded or each
individual paragraph as it is inserted.
4. You need to determine if the selections in the list are properties or methods. You also
need to determine how to use them. If it is a property, what is the property that would
be set? If it is a method how is it invoked?
12-27
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
5. After coming up with the new code the document will look as follows:
Two new lines were added to perform bolding and inserting new paragraphs. The
bolding is done with a property that has a True or False value. The inserting of a new
paragraph is done with a method. Your result could be different.
12-28
*()DQXF
ZZZML\LWHFKFRP
Student Guide
.Documents.Open ("C:\dynamics\APP\MaintLog.doc")
.ActiveDocument.Range.Font.Bold = True
.ActiveDocument.Paragraphs.Add.Range.InsertParagraph
.ActiveDocument.Paragraphs.Add.Range.InsertAfter Msg3LineStr
.ActiveDocument.saveas "C:\dynamics\APP\MaintLog.doc"
.quit
End With
OpenWord:
Set Wordapp = CreateObject("Word.Application")
Resume Next
End Sub
The bold property is set to True. The Range usage bolds the complete document.
The InsertParagraph method inserts a new paragraph each time the code is run.
12-29
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
12-30
*()DQXF
12.8.
ZZZML\LWHFKFRP
Student Guide
2. Explain what the Dim statement does differently then the Set statement?
4. When is an application used in automation removed from memory? What is the method
that removes the application from memory?
12-31
*()DQXF
12.8.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
12-32
*()DQXF
13.
ZZZML\LWHFKFRP
Student Guide
Chapter 13
ActiveX, Linking and Embedding
13-1
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
ActiveX Controls
13-2
*()DQXF
13.1.
ZZZML\LWHFKFRP
Student Guide
ActiveX ________________________________________________
ActiveX Controls
OLE Automation
Compound Documents
B. ActiveX
Evolved from the OLE development standard (OLE for the internet)
C. ActiveX Document
iFIX Picture
Event Schedule
D. ActiveX Control
An object that can be manipulated by the user to perform an action i.e. a control
ActiveX controls can be used from within any ActiveX compliant application
13-3
*()DQXF
13.2.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
A. Notes
ActiveX controls allows for routines to be used without knowing how the
container application works
VBA can access ActiveX objects as any other object in the container
The container vendor may provide some ActiveX controls as part their own
application
ActiveX controls can come from other sources like the Web and can be used for
free or require a purchase and possibly a license to use them
Typically ActiveX controls include a .OCX file along with .DLLs and help files
13-4
*()DQXF
13.2.
ZZZML\LWHFKFRP
Student Guide
ActiveX component
(umbrella term for ActiveX
document, ActiveX control, and
ActiveX code component)
ActiveX control
ActiveX document
ActiveX scripting
Automation
OLE Automation
Figure 13-1: ActiveX and OLE Terms
13-5
*()DQXF
13.3.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
A. Notes
iFIX uses ActiveX controls as tools to help in building a project and as user
interface objects
The Expression Editor and the Alarm Summary object are examples of built in
controls that can be used in your project
The Alarm Summary object and the Expression Editor have exposed properties
displayed in a custom property dialog and the properties window
-
Because they are ActiveX controls you could drop them in another
container like Word and the controls will function normally
13-6
*()DQXF
13.3.
ZZZML\LWHFKFRP
Student Guide
13-7
*()DQXF
13.4.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
A. ActiveX controls
ActiveX controls have their own methods, properties and events and are available
immediately as the control is added
ActiveX controls include a custom property dialog and the ability to use the
property window as well
-
Some containers can only show the custom property dialog and do not
include the ability to use property window
The custom property dialog can be accessed from the property window by
selecting the filed Custom and the dialog will appear
VBA can be used to manipulate the ActiveX controls properties, methods and
events
ActiveX controls can have their own object reference library that will be
referenced if Automation is used to work with the object
13-8
*()DQXF
13.4.
ZZZML\LWHFKFRP
Student Guide
13-9
*()DQXF
13.4.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Most of the time after installing ActiveX controls, the methods, properties and
events have to be browsed to determine how to use them
Example:
The control may allow for the attachment of a source like a iFIX database
tag or only have a value property to be set
Also be aware that installing an ActiveX control does not necessarily mean it is
available for use
-
Installing an ActiveX control into iFIX in most case will be successful but there is
not a total guarantee
Whoever wrote the code may not have done the best job in coding
13-10
*()DQXF
13.4.
ZZZML\LWHFKFRP
Student Guide
Figure 13-7: Using Calendar ActiveX Control to Set the Chart Object
13-11
*()DQXF
13.4.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
VBE forms toolbox contains ActiveX controls such as the listbox and the
combobox
Only ActiveX controls that will be used within forms should be added
Add any controls that exist in a form already by dragging them from the
form onto the new page
Add new controls by selecting the new page, then RMC and select
additional controls, then select from available list
13-12
*()DQXF
13.4.
ZZZML\LWHFKFRP
Student Guide
13-13
*()DQXF
13.5.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
13-14
*()DQXF
13.5.
ZZZML\LWHFKFRP
Student Guide
13-15
*()DQXF
13.6.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
OLE ___________________________________________________
A. OLE provides the ability to do behind the scenes data exchange and manipulation of
other programs
OLE
offers the ability to expose the object model used in other applications
offers ability to work with objects that are supported by other applications
Objects are data, text, graphics, sounds, spreadsheets, almost anything plus
functions used to create, access and use the data
Client application is the application that is used to store, link or embed object
Compound documents are documents that contain there own data plus an object
or objects created by other applications
-
The Client application does not have to know anything about the
data format.
The client only needs to know the name of the server that created
the data and how to display it
13-16
*()DQXF
13.6.
ZZZML\LWHFKFRP
Student Guide
OLE ___________________________________________________
D. Object Linking
Linking is one method to insert an object into a file from a client application
Source file resides in a separate file and can be edited by the server or client
Editing the compound document in the client is as easy as double clicking on the
object and the server loads the source file
E. Object Embedding
Embedding inserts the object and the data along with registry information and
metafile information so everything is there to display and work with the object
Note some applications are server only and cannot create objects
13-17
*()DQXF
13.7.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
The recipient client must have the server application installed to view the
compound document
13-18
*()DQXF
13.8.
ZZZML\LWHFKFRP
Student Guide
1. iFIX provides you with a Chart Object, an Alarm Summary Object, a Variable Object, a
Timer Object and an Event Object. Which of these Objects are ActiveX controls?
2. What do OLE, COM, and DCOM stand for? Are all three basically the same
technology?
4. Clearly all ActiveX controls are objects. They are pre-packaged pieces of functionality,
which expose their properties, methods, and events to our component architecture in the
form of OLE automation interfaces. So if all ActiveX controls are objects, are all the
objects we use in the iFIX WorkSpace ActiveX controls?
5. What is the total distance between the earth and the sun? What planet almost lost its
status as a planet if the definition rules were followed?
13-19
*()DQXF
13.8.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
13-20
*()DQXF
14.
ZZZML\LWHFKFRP
Student Guide
Chapter 14
Accessing Relational Databases
14-1
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
14-2
*()DQXF
14.1.
ZZZML\LWHFKFRP
Student Guide
Overview_______________________________________________
Drawbacks to DAO
-
such as events
this is not the fastest way to get data from a database such as
Oracle
since VBA is not compiled code, VBA scripts written using DAO
will not run on machines without one of these programs installed
14-3
*()DQXF
14.1.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Overview_______________________________________________
RDO has a similar object model to DAO, but adds features such as asynchronous
processing and events
Drawbacks:
-
14-4
*()DQXF
14.1.
ZZZML\LWHFKFRP
Student Guide
Overview_______________________________________________
Microsoft designed ADO in an effort to combine the best features of DAO and
RDO
-
Microsoft has publicly stated that ADO will eventually replace these older
methods
OLE DB Providers can be written for any data, from a legacy mainframe
database to an .INI file
ADO flattens the complex RDO (or DAO) object model and provides the
same, or more, functionality with fewer, more powerful objects
ADO is built into Visual Basic 6.0, but is also currently available as a separate
download from Microsoft's website
It is legal to install and use ADO on all iFIX nodes without purchasing
extra software
Intellution recommends that ADO is used for all iFIX VBA scripts that deal with
database access
14-5
*()DQXF
14.2.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
A. Overview
DAO is an object-based data access interface that provides access to SQL data
sources through VBA
To use DAO within iFIX, a reference to the Microsoft DAO object library must
be set
Note:
Microsoft DAO 3.5 no longer supports some of the objects, properties, and
methods that were supported in earlier versions of Microsoft DAO
Once you have set a reference to the Microsoft DAO object library, you can view
the DAO objects in the Object Browser
-
ODBCDirect
see Figure 14-1 for an illustration of how DAO uses Jet and ODBCDirect
to access a SQL data source
14-6
*()DQXF
14.2.
ZZZML\LWHFKFRP
Student Guide
Figure 14-1: Accessing SQL Data Sources with DAO Jet versus DAO ODBCDirect
14-7
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Jet was designed primarily to access native Jet/Access (.MDB) databases and
selected ISAM databases
-
Programmatic DDL
-
provides table definitions and the ability to create or modify tables using
Data Definition Language (DDL)
C. Jet Disadvantages
Jet loads the Microsoft Jet database engine even when it is not a Jet
database being accessed
Since calls must be passed through the Jet database engine before reaching
the ODBC API, Jet is slower than ODBCDirect
14-8
*()DQXF
ZZZML\LWHFKFRP
Student Guide
eliminates the resources required by Jet to load the Jet database engine
Asynchronous queries
-
caches Recordset changes locally and submits the changes to the server in
a single batch
14-9
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
The following example queries a relational database using DAO and displays the
database information in a picture
'Create a recordset.
Dim rs As Recordset
Set rs = db.OpenRecordset("Packaging", dbOpenDynaset)
14-10
*()DQXF
ZZZML\LWHFKFRP
Student Guide
DownTimeGrid.Col = 2
DownTimeGrid.Text = "Data Source"
DownTimeGrid.ColWidth(2) = 4500
DownTimeGrid.Col = 3
DownTimeGrid.Text = "Description"
DownTimeGrid.ColWidth(3) = 5500
DownTimeGrid.Col = 4
DownTimeGrid.Text = "Period"
'Loop through the data and display it.
Dim r As Integer
Dim c As Integer
r = 1
While rs.EOF <> True
DownTimeGrid.Row = r
For c = 0 To 4
DownTimeGrid.Col = c
If rs.Fields(c + 1) <> "" Then
DownTimeGrid.Text = rs.Fields(c + 1)
End If
If c = 0 Then
'This formats the time from ACCESS.
DownTimeGrid.Text = Format(rs.Fields (c + 1), "h:mm:ss AM/PM")
End If
If c = 1 Then
'This formats the date from ACCESS.
DownTimeGrid.Text = Format(rs.Fields (c + 1), " dddd, mmmm, yyyy")
End If
Next c
r = r + 1
rs.MoveNext
Wend
Set rs = Nothing
Set db = Nothing
Set wrkSpace = Nothing
End Sub
14-11
*()DQXF
14.3.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
The first step is to reference the ActiveX Data Objects Library in a picture's
project
Do this by selecting the References command from the VBE Tools menu and then
selecting the ADO type library
The object variables are declared at the Module level, which means that
they are available in all of the other routines in this example
14-12
*()DQXF
14.3.
ZZZML\LWHFKFRP
Student Guide
'General Declarations
'This stores the link to the database.
Dim conODBC As ADODB.Connection
'This stores the results of the query.
Dim adoRS As ADODB.Recordset
End Sub
14-13
*()DQXF
14.3.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
To get the data out of the recordset for display, a spreadsheet or grid is handy
Figure 14-4 shows how to copy the data into the grid
MSFlexGrid1.ColWidth(0) = 1150
MSFlexGrid1.ColWidth(1) = 4000
MSFlexGrid1.ColWidth(2) = 1250
MSFlexGrid1.ColWidth(3) = 1450
MSFlexGrid1.ColWidth(4) = 2050
MSFlexGrid1.ColWidth(5) = 1150
RecipeID.Value = ""
RecipeName.Value = ""
BatchSize.Value = ""
MilkQuan.Value = ""
ChocQuan.Value = ""
MixTime.Value = ""
End Sub
14-14
*()DQXF
14.3.
ZZZML\LWHFKFRP
Student Guide
Private Sub
Dim iRow
Dim iCol
On Error
LoadRecipes()
As Integer
As Integer
GoTo ErrorHandler
Next iCol
Wend
'The row number will show the number of records returned.
RecipeCount.Value = Str(iRow)
Exit Sub
ErrorHandler:
HandleError
End Sub
14-15
*()DQXF
14.3.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
If the recordset is not opened as read-only, records can be added to the database
through ADO
Exit Sub
End If
adoRS.AddNew 'Adds a new record to the recordset.
ErrorHandler:
'Handle the error returned if any columns need
'to be unique (such as recipe name) but weren't.
If Err.Number = -2147217887 Then
MsgBox "Recipe Names Must be Unique", _
vbExclamation, "RecipeControl"
Exit Sub
End If
HandleError
End Sub
14-16
*()DQXF
14.3.
ZZZML\LWHFKFRP
Student Guide
If the recordset is not read-only, values in a record can be changed and written to
with ADO
End Sub
14-17
*()DQXF
14.3.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
If the recordset is not read-only, records in the database can be deleted with ADO
ErrorHandler:
HandleError
End Sub
14-18
*()DQXF
ZZZML\LWHFKFRP
Intellut on
Date: _______________________________
Instructor: ______________________________
Please indicate your level of interest in these aspects of using VBA with iFIX:
Low
High
Why?
Using Forms
______________________________________
Collections and Groups
______________________________________
Accessing the PDB
______________________________________
Error Handling
______________________________________
Debugging
______________________________________
Of all course topics, which were of the most value? _____________________________________
Which were of the least value? _____________________________________________________
Comments: ____________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
Totally
Unfamiliar
Completely
Competent
Poor
OK
Superior
Comments: ____________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
Poor
OK
Superior
*()DQXF
ZZZML\LWHFKFRP
Additional Comments:
*()DQXF
ZZZML\LWHFKFRP
Student Guide
A. Glossary _________________________________________________
Appendix A
Glossary
A-1
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
A. Glossary _________________________________________________
ActiveX - Microsoft's brand name for the technologies that enable interoperability using the
Component Object Model (COM).
ActiveX Component - Physical file (for example, .exe, .dll, .ocx) that contains classes, which
are definitions of objects.
ActiveX Control - An object that you place on a form to enable or enhance a user's
interaction with an application. These controls have an .ocx file name extension
ActiveX Document - An application that can be viewed in another.
Alarm Destination - An enabled service on a node where alarms are routed. Alarm
destinations include Alarm Printers, the Alarm File Service, the Alarm Summary
Service, and the Alarm Network Service.
Alarm Priority - The relative severity of an alarm. You can assign a priority of Low,
Medium, or High to alarms.
Alarm Queue - Reserved memory that holds incoming alarm messages until an alarm service
can process them. The size of the queue determines how many alarms can be stored.
If the queue overflows, the oldest unprocessed alarms are discarded.
Alarming - The process by which blocks receive process data, compare the data against predefined alarm limits, and react to those process values that exceed these limits.
Alarms Path - Stores alarm data files and security log files. By default, the alarms path is set
to C:\DYNAMICS\ALM.
A-2
*()DQXF
ZZZML\LWHFKFRP
Student Guide
A. Glossary _________________________________________________
Application User - An operator you want automatically logged into iFIX. Once logged in,
operators have access to the privileges assigned to the specified user account.
Automatic Mode - A database tag mode in which the tag is scanned by the Scan, Alarm, and
Control (SAC) program. In this mode, the tag accepts data only from the poll table or
other tags.
Base Path - Stores all iFIX executable files. By default, this path is set to C:\DYNAMICS.
Block - Individual unit of instructions capable of receiving, checking, manipulating, and
outputting process values. A block can also compare a process value against an alarm
limit and perform calculations based on a specific process value.
Block Field - A location in a block that holds process data. Blocks have many fields such as
their current value, name, scan time, EGU range, alarm limits, alarm areas, and
security areas.
Block Type - Blocks are organized into types based upon similar function. Blocks capable of
performing batch functions are of the batch type; blocks capable of performing
statistical calculations are of the statistical type, and so forth. The types of blocks
available to your system is dependent upon the options you purchased with iFIX.
Chain - Two or more blocks connected to each other. Your goal in creating a database is to
chain blocks in a sequence so that each block performs a specific task and then passes
its information on to one or more appropriate blocks.
Collection Group - A set of tagnames for a selected node that identifies the database blocks
that contain process data required for trending. You can define up to 64 collection
groups with 80 different tags in each collection group. The Historical Assign program
stores collection groups in the historical data path in the following format:
HTRGRP##.DAT, where ## represents the number of the group (01-64).
A-3
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
A. Glossary _________________________________________________
Color Threshold - Either a color and value combination (Color by Value) or a color and
alarm state combination (Color by Alarm or Color by Latched Alarm). For a value
threshold, you specify the upper limit of the range of values that correspond to a color.
When the value of the target database field is less than or equal to the threshold, but
greater than all lower thresholds, the foreground, edge, or background color of the
object changes to the defined color. For an alarm threshold, you specify the color that
correspond to an alarm state. When the target database tag is in an alarm state, the
object changes to the defined color.
COM - Component Object Model
Cross-Hair Cursor - The cross-hair cursor creates rectangles, ovals, lines, polygons, and
polylines.
Data Collection Rate - Defines how often the Historical Collect program accumulates values
for the tagnames selected in a collection group.
Data Source - A reference to a source of information, such as iFIX tagnames and historical
files, or other OPC-compliant data servers. Additionally, a data source may consist of
iFIX objects (such as shapes, charts, and variables) or 3rd party OLE controls.
Database Path - Stores process database files, Database Builder configuration files, and I/O
driver configuration files. By default, this path is set to C:\DYNAMICS\PDB.
A-4
*()DQXF
ZZZML\LWHFKFRP
Student Guide
A. Glossary _________________________________________________
Dynamo - A reusable graphic, stored in a set, that contains object properties. When you
paste a Dynamo into a picture, you are prompted to enter the appropriate property
values for the current picture. In addition to the standard iFIX Dynamos, you can
convert custom-built objects, links, and application scripts, such as pumps, valves, and
charts into Dynamos.
Easy Database Access (EDA) - A library of subroutines that provides easy access to iFIX
data. EDA handles the details of memory management, error detection and recovery,
networking, and so forth.
EGU Range - The maximum and minimum process values the process hardware can measure.
Events - Actions that an 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
Executable - The name of the file that runs a iFIX or a third party application. For example,
RECIPE.EXE or EXCEL.EXE.
The executable file name must include path
information. A string variable can replace this parameter.
Exception-Based Processing - Instructions that tell the Scan, Alarm, and Control (SAC)
program to process blocks by exception rather than a scheduled time interval. The
Analog Input, Analog Alarm, Digital Input, and Digital Alarm blocks can use this
processing method:
Font - A text design. The characters in a text object all have a common design.
A-5
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
A. Glossary _________________________________________________
Grid - The grid is a tool for helping you lay out and align objects in a picture. When you
enable the grid, evenly spaced dots appear on your screen. These dots represent the
intersection of invisible guidelines.
Group Account - A group account defines the application features and security areas for
multiple users. By creating group accounts, you define the account privileges most
commonly needed for two or more people.
Group Membership - Group membership defines the group account(s) that a user is assigned
to in a user account. Once assigned to a group account, a user may have access to all
the application features and security areas defined for the group.
Grouped Objects - A set of objects that has been joined together with the Group command.
Once you group objects into one single object, you can manipulate the group like any
other object. You can move, cut, paste, copy, stretch, and assign animations to a
group, using the same methods used for individual objects.
Handles - Small squares located on the corners and sides of an object that you have selected
with the mouse. Handles allow you to resize an object horizontally, vertically, or both
ways at the same time by dragging the appropriate handle. An object with solid
handles has animations. An object with hollow handles does not have dynamic
properties.
Historical Data Path - Stores historical data files from which the Historical Collect
application creates a unique subdirectory in this directory for each node data is being
collected, and names the subdirectory according to the name of the node. By default,
the historical data path is set to C:\DYNAMICS\HTRDATA.
Historical Path - Stores the configuration files of Historical Assign and Historical Collect.
By default, the historical path is set to C:\DYNAMICS\HTR
I-Beam Cursor - Marks the start of a new text object or places the insertion cursor within an
existing text object.
A-6
*()DQXF
ZZZML\LWHFKFRP
Student Guide
A. Glossary _________________________________________________
Language Path - Stores the language files used to create dialog boxes and help files. If you
choose to implement a native language other than English, the new language and help
files replace the files found in this directory. By default, this path is set to
C:\DYNAMICS\NLS.
Line Style Marker - A line style marker, defined in the Line Style dialog box, displays on the
trend line and is used to distinguish between overlapping trend lines or when printing
in black and white. Historical data pens must either use a line style marker or show a
trend line, or both.
Links - Real-time connections to data points in the process database that are used to display
or process information.
Literal Pattern - A literal pattern generates a literal string of text for a block field. Literal
patterns can contain up to 255 characters and do not require quotation marks. For
example, you can enter alarms, elapsed time, and analog input from tank A as literal
patterns.
Local Path - Stores configuration files associated with the local computer, including the SCU
and Security application files. By default, this path is set to C:\Dynamics\LOCAL.
Logical Node Name - The name configured in a View node's and blind SCADA's SCU that
represents a primary and backup SCADA pair.
Manual Mode - A database tag mode in which operators can manually change the value of a
tag through links in the WorkSpace.
Master Recipe Path - Stores master recipe, master recipe error, and master recipe report
files for the Recipe application. By default, this path is set to C:\DYNAMICS\RCM.
Methods VBA Subroutines that effect the behavior of object
NetBEUI - Microsoft's implementation of NetBIOS.
NetBIOS - An API specification, not an implementation, of a network programming
interface.
A-7
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
A. Glossary _________________________________________________
Network Path - A network path is made up of a protocol and LAN card or modem. For
example: NetBEUI over one LAN card, NetBEUI over a RAS "card", or TCP/IP
over one LAN card.
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
Off Scan Status - A tag with an off scan status is not processed by the Scan, Alarm, and
Control (SAC) program. When a tag is off scan, its associated database chain is also
off scan.
OLE - Object Linking and Embedding
On Scan Status - A tag with an on scan status is being processed by the Scan, Alarm, and
Control (SAC) program every scan cycle. When a tag is on scan, its associated
database chain is also on scan.
One Shot Processing - One shot processing instructs the Scan, Alarm, and Control (SAC)
program to process a block once. This processing method is similar to exceptionbased processing, except that the block will not trigger again unless SAC is restarted,
the database is reloaded, or the block is turned off scan and then turned back on scan.
Any block with a scan time can be configured for one shot processing.
A-8
*()DQXF
ZZZML\LWHFKFRP
Student Guide
A. Glossary _________________________________________________
Primary Block - A block that receives data from an I/O driver or OPC server and includes a
scan time. Primary blocks are usually associated with one or more pieces of I/O
hardware and are always the first block in a chain.
Process Database - A data file that holds all the data from your process hardware. It is the
primary source of data for most iFIX applications.
Property - Characteristics of an object
Query - A request to Database Manager to display one or more blocks from the database.
Remote Node - Any node on the network that is not the local node.
Resolve - Resolving is a method to optimize the speed at which pictures open in the run-time
environment. Database information for each tag in a picture is saved as part of the file
on disk. When a picture is displayed in the run-time environment, and the database
information is not up to date, the WorkSpace has to query the database and resolve
the tag definitions; a time consuming process. Resolving in the configuration
environment eliminates the need for the WorkSpace to query the database. The end
result is that the picture opens faster in the run-time environment.
Scan, Alarm, and Control (SAC) - A program that retrieves process information from an
I/O driver or OPC server. Using the data it receives, SAC updates blocks in the
database and process alarms. SAC also returns corrective values from the database to
a control device.
Scan Time - A user-defined interval at which the Scan, Alarm, and Control (SAC) program
processes a block and any blocks chained to it.
A-9
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
A. Glossary _________________________________________________
SCU File - The SCU file contains information that the iFIX Startup program needs to
configure your node. When you run Startup, it reads the SCU file and uses the
information to run several system tasks. iFIX only uses the SCU file during startup, so
most changes you make to the file while the system is running will not take effect until
you stop and restart iFIX.
Secondary Block - A block that receives input from an upstream block and performs a
specific function with the input. For example, a secondary block can perform a
calculation or store several successive inputs.
Security Area - A physical or functional division of your process that allows you to restrict
access to schedules, recipes, operator displays, and write-protect database blocks.
Security areas can be process hardware (such as pumps or ovens) or utilities (such as
fuel, water, or steam), or maintenance functions. You can define up to 254 security
areas, which are identified by number. Associated with each number is a name of up
to 20 alphanumeric characters. By default, iFIX names the first 16 security areas A
through P.
The Simulation (SIM) Driver - A matrix of addresses where values are written to and read
from. If one block writes to a specific address, other blocks can read the same value
from the same address. SIM points are saved in the process database itself but are
cleared when SAC is started or when you reload the database. Refer to the Building a
SCADA System manual for more information.
Tagname - The information needed to access database data. A tagname consists of a node
name, database block (tag) name, and field name in this format: NODE:TAG.FIELD
User Account - Provides individual access to group accounts, security areas, and application
features. Each user account is identified by a full name, login name, optional password
and optional timeout specification. The Security Configuration program lets you
specify a user account to automatically log in an operator or you can have each user
log in manually with the Security Login program.
A-10
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Appendix B
File I/O
B-1
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
To work with the contents of a file, the file must first be opened
-
See Figure B-1 for details on the parts of the Open Statement
C. Important Note:
In Binary, Input, and Random modes, a file can be opened using a different file
number without first closing the file
In Append and Output modes, a file must be closed before opening it with a
different file number
D. Additional Notes
You must open a file before any I/O operation can be performed on it
Open allocates a buffer for I/O to the file and determines the mode of access to
use with the buffer
If the file specified by pathname doesn't exist, it is created when a file is opened for
Append, Binary, Output, or Random modes
If the file is already opened by another process and the specified type of access is
not allowed, the Open operation fails and an error occurs
B-2
*()DQXF
B.1.
ZZZML\LWHFKFRP
Student Guide
Part
Description
pathname
mode
access
lock
filenumber
reclength
Mode
Description
Append
Binary
Input
Output
Random
Used to read and write data to a file without closing it. Random
access files keep data in records, which makes it easy to locate
information quickly.
Figure B-2: File Access Mode Descriptions
B-3
*()DQXF
B.1.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
It Returns an Integer representing the next file number available for use by the
Open statement
Syntax
myVar = FreeFile[(rangenumber)]
-
Use the integer variable in place of an actual value in the Open Statement
-
F. Closing a file
Syntax
Close [filenumberlist]
Additional Notes
-
When files are closed that were opened for Output or Append, the final
buffer of output is written to the operating system buffer for that file
B-4
*()DQXF
B.1.
ZZZML\LWHFKFRP
Student Guide
Const FileNum = 2
Open "TESTFILE" For Binary Access Write As FileNum
' Close before reopening in another mode.
Close FileNum
Type Record
ID As Integer
Name As String * 20
End Type
' This example uses the FreeFile function to open five files for
' output within the loop, and some sample data is written to each.
Dim MyIndex, FileNumber
For MyIndex = 1 To 5
' Loop 5 times.
FileNumber = FreeFile
' Get unused file number.
Open "TEST" & MyIndex For Append As #FileNumber
Write #FileNumber, "This is a sample."
' Output text.
Close #FileNumber
' Close file.
Next MyIndex
B-5
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Read Commands:
-
Write Commands
-
B. Notes
As discussed, the Open statement lets you create and access files directly
Sequential access (Input, Output, and Append modes) is used for writing
text files, such as error logs and reports
Random access (Random mode) is used to read and write data to a file
without closing it
Binary access (Binary mode) is used to read or write to any byte position in
a file, such as storing or displaying a bitmap image
Figure B-4 shows the statements typically used when writing data to and reading
data from files
Access Type
Writing Data
Reading Data
Sequential
Print #, Write #
Input, Input #
Random
Put
Get
Binary
Put
Input, Get
B-6
*()DQXF
B.2.1.
ZZZML\LWHFKFRP
Student Guide
A. Put Statement
Data written with Put is usually read from a file with Get
Syntax
Put [#]filenumber, [recnumber], varname
-
filenumber Required
recnumber Optional
varname Required
If recnumber is omitted, the next record or byte after the last Get or Put statement
is written
B-7
*()DQXF
B.2.2.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
B. Get Statement
Syntax
Get [#]filenumber, [recnumber], varname
-
filenumber Required
recnumber Optional
varname Required
If recnumber is omitted, the next record or byte following the last Get or Put
statement is read
B-8
*()DQXF
B.2.3.
ZZZML\LWHFKFRP
Student Guide
A. Input Statement
Returns String containing characters from a file opened in Input or Binary mode
Data read with the Input function is usually written to a file with Print # or Put
-
Use this function only with files opened in Input or Binary mode
Unlike Input #, the Input function returns all of the characters it reads, including
commas, carriage returns, linefeeds, quotation marks, and leading spaces
Syntax
Input(number, [#]filenumber)
-
number Required
filenumber Required
' this example assumes that the file has a few lines of
' data. The Input function to read one character at a
' time from a file and print it to the Debug w indow
Dim MyChar
Open "c:\dynamics\file1.txt" For Input As #1
Do While Not EOF(1)
' Loop until end of file.
MyChar = Input(1, #1)
' Get one character.
Debug.Print MyChar
' Print to Debug window.
Loop
Close #1
' Close file.
B-9
*()DQXF
B.2.4.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
A. Input # Statement
Reads data from an open sequential file and assigns the data to variables.
Use this statement only with files opened in Input or Binary mode
Syntax
Input #filenumber, varlist
-
filenumber Required
varlist Required
' this example assumes that the file has a few lines of
' data containing a string in quotations and a number
' separated by a comma, for exa mple, ("Hello", 234)
Dim MyString, MyNumber
Open "c:\dynamics\file2.txt" For Input As #1
Do While Not EOF(1)
Input #1, MyString, MyNumber
Debug.Print MyString, MyNumber
Loop
Close #1
B-10
*()DQXF
B.2.5.
ZZZML\LWHFKFRP
Student Guide
A. Write # Statement
Data written with Write # is usually read from a file with Input #
Unlike the Print # statement, the Write # statement inserts commas between items
and quotation marks around strings as they are written to the file
-
Write # inserts a newline character after it has written the final character in
outputlist to the file
Syntax
Write #filenumber, [outputlist]
-
filenumber Required
outputlist Optional
B-11
*()DQXF
B.2.6.
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Print # Statement_______________________________________
A. Print # Statement
Data written with Print # is usually read from a file with Input # or Input
If the data from a file is to be read using the Input # statement, use the Write #
statement instead of the Print # statement to write the data to the file
-
using Write # ensures the integrity of each separate data field by properly
delimiting it, so it can be read back in using Input #
Syntax
Print #filenumber, [outputlist]
-
filenumber Required
outputlist Optional
' This example uses the Print # statement to write data to a file.
Open " c:\dynamics\file4.txt " For Outpu t As #1
Print #1, "Hello" ; " " ; "World"
' Separate strings with space.
Print #1, "Zone 1"; Tab ; "Zone 2"
' Print in two print zones.
Print #1,
' Print blank line to file.
Print #1, Spc(5) ; "5 leading spaces " ' Print five leading spaces.
Print #1, Tab(10) ; "Hello"
' Print word at column 10.
Dim MyBool, MyDate, MyNull, MyError
MyBool = False : MyDate = #January 1, 2000# : MyNull = Null
MyError = CVErr(32767)
Print #1, MyBool ; " is a Boolean value"
Print #1, MyDate ; " is a date"
Print #1, MyNull ; " is a null value"
Print #1, MyError ; " is an error value"
Close #1
B-12
*()DQXF
ZZZML\LWHFKFRP
Student Guide
C. Additional Notes___________________________________________
Appendix C
Additional Notes
C-1
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
AboutBox
AckAlarmPage
ActivateWorkspaceUI
AddEventHandler
AddLegendItem
AddObject
AddPoint
ApplyProperty
BringToFront
CanConstruct
ClearUndo
Commit
ConnectedPropertyCount
ConvertSecurityAreaNameToNumber
Copy
CreateFromDialog
CreateWithMouse
DeActivateWorkspaceUI
DelAlarm
DeleteImage
DeletePoint
DemandFire
DestroyObject
Disconnect
DoesPropertyHaveTargets
DumpProperties
EditPicture
ExchangePenPositions
FindInString
FindReplaceInObject
FitDocumentToWindow
FixCheckApplicationAccess
FixCheckSecurityEnabled
FixLogin
FontProperties
AckAlarm
AckAllAlarms
Add
AddImage
AddLevel
AddPen
Align
AutoScaleDisplayLimits
BuildObject
Clear
Close
Connect
Construct
ConvertSecurityAreaNumberToName
CopyAsBitmap
CreateFromProgID
Cut
DefaultView
DeleteAllAlarms
DeletePen
DeleteSelectedObjects
DeselectObject
DisableNonSelectionEvents
DisplaysControlPoints
DoMenuCommand
Duplicate
Enable
FindAndReplaceDialog
FindObject
FindReplaceInString
FitWindowToDocument
FixCheckAreaAccess
FixGetUserInfo
FixLogout
FullView
C-2
*()DQXF
ZZZML\LWHFKFRP
Student Guide
GetBoundRect
GetConnectionInformation
GetCurrentValue
GetDuration
GetEventHandlerIndex
GetInterval
GetObjectInfo
GetPointAt
GetProperty
GetPropertyTargets
GetSelectedNodeTag
GetSelectedUserDefFields
GetStatusFont
GetTimeCursorInfo
Group
InsertPoint
IsConnected
Item
ListMethods
LoadImage
LogicalToUserFormPoint
Modify
Move
ParseConnectionSource
PasteSpecial
PercentageToLogical
PixelToPercentage
Quit
Refresh
Remove
RemoveItem
RemoveLevel
ReplaceDocument
ResetChartData
ResetStats
GetColumnInfo
GetConnectionParameters
GetDeviceRect
GetErrorString
GetIndirectionInfo
GetLevel
GetPenDataArray
GetPriorityColor
GetPropertyAttributes
GetSelectedAlmExt
GetSelectedRow
GetStatusColor
GetTimeBeforeNow
GetWindowLocation
HiLoDisplay
IsColorSelectionVisible
IsEmpty
ListEvents
ListProperties
LogicalToPercentage
MakeSameSize
ModifyColumnLength
Open
Paste
Pause
PercentageToPixel
PrintOut
Read
RefreshChartData
RemoveAllLevels
RemoveLegendItem
RemoveObject
ReplaceInString
ResetObjectStats
ResetZoom
C-3
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
Resume
RunObject
SaveToHistoryList
ScrollForward
ScrollTimeForward
SelectAll
SendOperatorMessage
SetCurrentValue
SetDISPID
SetFocusToComboBox
SetInterval
SetPenDataArray
SetPriorityColor
SetScriptWindow
SetStatusColor
SetStringFormat
SetTimeBeforeNow
SetWindowLocation
ShowBrowseDialog
ShowColorSelection
ShowTaskWizard
SnapObjectsToGrid
StartEvent
StickToCursor
StopTimer
SwitchMode
UIDeActivate
UndoTransaction
UpdateBackgroundObject
UserFormPointToLogical
ValueTimeFromXY
XYFromValueTime
Zoom
Rotate
Save
ScrollBack
ScrollTimeBack
Select
SelectObject
SendToBack
SetDispatch
SetDuration
SetIndirectionInfo
SetNumericFormat
SetPointAt
SetProperty
SetSource
SetStatusFont
SetTabSelection
SetTimeCursorTime
ShowAnimations
ShowColorBox
ShowCustomPages
ShowVisualBasicEditor
SpaceEvenly
StartTimer
StopEvent
Stretch
UIActivate
Undo
UnGroup
UpdateConnectionParameters
ValidateSource
Write
XYHitTest
C-4
*()DQXF
ZZZML\LWHFKFRP
Student Guide
Secant
Sec(X) = 1 / Cos(X)
Cosecant
Cosec(X) = 1 / Sin(X)
Cotangent
Cotan(X) = 1 / Tan(X)
Inverse Sine
Inverse Cosine
Inverse Secant
Inverse Cosecant
Inverse Cotangent
Hyperbolic Sine
Hyperbolic Cosine
Hyperbolic Tangent
Hyperbolic Secant
Inverse Hyperbolic
Sine
Inverse Hyperbolic
Cosine
Inverse Hyperbolic
Tangent
Inverse Hyperbolic
Secant
HArcsec(X) = Log((Sqr(-X * X + 1) + 1) / X)
Inverse Hyperbolic
Cosecant
Inverse Hyperbolic
Cotangent
Logarithm to base N
C-5
*()DQXF
ZZZML\LWHFKFRP
Intellution
Dynamics iFIX
C. Additional Notes___________________________________________
C-6