You are on page 1of 13

KNOWLEDGEBASE

Using VBA with FT View SE


Hands on Lab Excerpt
Answer ID 51769
Manipulating a Trend with VBA

3 of 13

Using VBA with FactoryTalk View SE

Contents
Before you begin .........................................................................................................................................5
About this lab.................................................................................................................................................5
Tools & prerequisites.....................................................................................................................................5
Lab Setup ......................................................................................................................................................6
Document Conventions ..............................................................................................................................7
Starting FactoryTalk View Studio and the SE Client ...............................................................................8
Section 1: Trend Manipulation .................................................................................................................10
About This Section ......................................................................................................................................10
Observe Trending Display ...........................................................................................................................10
Add pens to the Trending Display ...............................................................................................................11
More trend options.......................................................................................................................................15

4 of 13

Before you begin

About this lab


This lab demonstrates how to extend capabilities of FactoryTalk View SE by using Visual Basic for
Applications (VBA). The lab is aimed at a broad range of users; attendees should be familiar with VBA
Integrated Development Environment (IDE) of FactoryTalk View SE and writing VBA code.
The main of this lab include:

configuring a Trending display by adding and removing pens at runtime

Tools & prerequisites


The following software has been used for the examples in this lab manual:
RSLogix 5000 v16.03
SoftLogix5800 v16.03
FactoryTalk Services Platform v2.10
FactoryTalk View SE v5.00
RSLinx Enterprise v5.00

5 of 13

The following FactoryTalk View and RSLogix 5000 files are available for this example in the Lab Files
subdirectory:
1. A complete FactoryTalk View v5.0 SE application with many VBA examples, including the one detailed
in this technote. This can be found in: _Complete SE Application\VBA_Lab_v1_0.apa

This lab manual steps you through the VBA_Lab_v1_0 application


and assumes you have it installed.

or 2. If you do NOT want to install the complete application and instead want to view each component
individually, they have been separated and included here:
RSLogix 5000 file:

RSLogix 5000\VBA_Lab.ACD

SE Displays:

SE Displays\Trending.gfx
SE Displays\Trending_Completed.gfx

Lab Setup
SoftLogix/RS Emulate/ControlLogix
Load the RSLogix 5000 application into your controller. The examples in this manual use slot 2. Put
the controller in Run Mode.
FactoryTalk View SE
Restore the FactoryTalk View back-up apa file or manually create the SE application using the
individual files included (see above)
Ensure that your RSLinx Enterprise topic exists, points to the controller, and has alarms and events
enabled. The examples in this manual use the topic name SoftLogix.

6 of 13

Document Conventions
Throughout this workbook, we have used the following conventions to help guide you through the lab
materials.

This style or symbol:

Indicates:

Words shown in bold italics


(e.g., RSLogix 5000 or OK)

Any item or button that you must click on, or a menu name
from which you must choose an option or command. This will
be an actual name of an item that you see on your screen or
in an example.

Words shown in bold italics,


enclosed in single quotes
(e.g., 'Controller1')

An item that you must type in the specified field. This is


information that you must supply based on your application
(e.g., a variable).
Note: When you type the text in the field, remember that you
do not need to type the quotes; simply type the words that
are contained within them (e.g., Controller1).
The text that appears inside a box is supplemental
information regarding the lab materials, but not information
that is required reading in order for you to complete the lab
exercises. The text that follows this symbol may provide you
with helpful hints that can make it easier for you to use this
product. Most often, authors use this Tip Text style for
important information they want their students to see.

Note: If the mouse button is not specified in the text, you should click on the left mouse button.

7 of 13

Starting FactoryTalk View Studio and the SE Client

1. From the Start menu, select FactoryTalk View Studio

2. Double-click Site Edition (Local) Icon.

3. Select the existing project called VBA_Lab and click the Open buttin

4. After the project opens maximize FactoryTalk View Studio

5. Expand the displays to show configured displays

8 of 13

6. Expand the height of the diagnostics bar to show 5 or 6 lines.Change it from a single line like this

to multiple lines like this

7. Click on the Launch SE Client icon from View Studio.

8. When prompted, select the C:\Lab Files\PV14 VBA Lab\VBA_Lab.cli configuration file.

9 of 13

Section 1: Trend Manipulation


RELATED KNOWLEDGEBASE ANSWER IDS
46417: Making TrendX pens invisible and visible

About This Section


In this section, you will learn how to manipulate a trend object by using VBA. Many pen properties can be
modified at runtime by the operator using buttons external to the trend. For example: pen min/max, color,
description, scale, and visibility. The TrendX object model allows you to add and remove pens, clear the
chart, create and delete snapshots, load and save templates, load historical data, and print the chart.
From the Trending display you can use the Object Browser in the VBA IDE to see a complete list of
properties and methods.

To allow an operator to select different trend pens at runtime, you will add VBA code to the Trending
display. The Trending display has combo boxes that are initialized with trend pens. You will add VBA
code to the Refresh Trend button so that when the operator clicks the button, the existing trend pens will
be removed and the selected trend pens will be added to the trend object. At runtime, you can use the
preconfigured Display Keys. The F5 key will refresh the Trending display so you can quickly test your
work. The F12 key will open the Trending_Completed display so that you can see how your display
should work once you have completed this section.

Observe Trending Display


1. Navigate to the VBA_Lab Client.

10 of 13

2. Select the Trend Manipulation button from the Footer or the Main Menu display.

3. Observe that

no trend pens are being displayed

combo box lists exist with pen/tag names

nothing happens when clicking on the refresh button

Add pens to the Trending Display


1. Navigate back to FactoryTalk View Studio.

2. Open the Trending display.


3. Enter Alt + F11 to navigate to the VBA IDE
4. Observe the following

objects have been exposed to VBA for you

the Load procedure for the Display object initializes the combo boxes with trend pens/tags

11 of 13

the Add_Trend_Pens function has been created for you

12 of 13

the Remove_Trend_Pens function has been created for you

the RefreshTrend_Button_Released procedure exists and has comments on what to do

5. Follow the instructions in the comments of the RefreshTrend_Button_Released procedure.

13 of 13

6. Select Debug > Compile Display Code from the VBA IDE menu.

7. Test your changes in View Studio, click the Test Display toolbar icon

8. Select pens and click the Refresh Trend button. Does it work?
9. Correct any errors you have until you get it working properly. If you need help, look at
Trending_Completed.
Note that pop up messages can easily be hidden by other windows. If it appears that nothing is
happening use the Alt-Tab key to look at open windows.
10. Click the Edit Display toolbar icon.

11. Save and close your Trending display.


12. Navigate back to the VBA_Lab Client and the Trend Manipulation screen.

13. Observe that no trend pens are being displayed.


14. Press the F5 key to refresh the Trending display.
15. Observe that there are trend pens when the display is first opened.
Warning about Test Display
While testing your display in View Studio, you are modifying the properties of the trend. You can
accidentally save unintended changes to the initial settings for the trend.

14 of 13

More trend options


1. While focus is on the Trending display, press the F12 key to see the Trending_Completed display.
2. Trending_Completed shows additional trend options that can be modified in VBA. If you would like
take some more time to examine the other trend options in Trending_Complete and try to recreate
those on your Trending display.

15 of 13