FTView Studio + VBA: how to read parameters from a Global Object?

MrR

Member
Join Date
May 2012
Location
Earth
Posts
1
Hi,

I'm working with Factory Talk Studio and VBA coding. So far, I have two questions. If someone could help me I would be really glad.
First, I have a global object which has a Touch animation and three parameters: Window, IndexNo and Text.

I've created a bunch of tags (HMI, not in PLC) named Index000 to Index100, all of them in Nav folder (Nav\Index001 for instance).

Suppose my parameters are #1 MyWindow, #2 100 and #3 MyButtonText.
My object runs "&Display #1; &Set Nav\Index#2 = 1".


My code needs to read the #2 parameter (IndexNo) so that it can write 0 or 1 in a specific Nav\Index###.

What I've done until now: I can read and write to HMI tags using
Code:
'Code 1:
Private Sub MyGObject_Click()
  IndexNumber = 100
  {Code here so that it will waits 10 seconds}
  If My_Group.Item("Nav\Index" & IndexNumber).Value = 1 Then
        My_Group.Item("Nav\Index" & IndexNumber).Value = 0
  End if
End Sub

What I really wanted:
Code:
'Code 2:
Private Sub MyGObject_Click()
  [B]IndexNumber = Me.Parameters(2)[/B]    'Reads #2 parameter and stores in IndexNumber variable
  {Code here so that it will waits 10 seconds}
  If My_Group.Item("Nav\Index" & IndexNumber).Value = 1 Then
        My_Group.Item("Nav\Index" & IndexNumber).Value = 0
  End if
End Sub

The code above won't work. How can I read #2 parameter? Is that possible?


Now my second obstacle: although time consuming, I could create a window with, say, 10 objects, ranging from My_Object001 to My_Object010. Then I would have 10 VB subs on a window and could change "Code 1"'s IndexNumber of each one to its right number, i.e. 001..010. Still, "Display" command (set in the Global Object) won't work when I use VB code (it works fine when I don't). Why?

I might be missing (correction: i'm sure i'm missing) something, since I'm new to FTView and VBA. So please, correct me if I made any mistake or if anything isn't clear.

Thank you very much for your attention.
 
Did you ever get a response or find a way to do this by reference? I would like to something similar, and cannot figure out an easy way to do it.
 
Solution

I had the same problem and found a workaround. Add one text object per parameter and set the Caption of each text object to be an embedded Numeric/String with the parameter. Then, you can access the .Caption property of the text from your VBA.

For example, i made two text objects, txtP1 and txtP2 to capture my two parameters. Setup the captions as #1 and #2 respectively. I used the insert Numeric, Literal, #1 with up to two digits to suit my application. I was able to set the Expose to VBA to Type Info Extension of those text objects and access via txtP1.Caption in the VBA code.

I dont know if there is a direct way to do it via the Object model, but I couldnt find one. Please post if anyone finds it.
 
Correction

The above solution I just posted only works for one instance of the object on a display because of the serial-auto-naming of additional objects with the same name.

I found a much easier solution. Embed any text you want to capture in the caption of the button being pressed. Then you can just refer to

ActiveElement.Caption

in the VBA click event of the button. If need be, you would have to put the button behind another object to hide this text.
 
The above solution I just posted only works for one instance of the object on a display because of the serial-auto-naming of additional objects with the same name.

I found a much easier solution. Embed any text you want to capture in the caption of the button being pressed. Then you can just refer to

ActiveElement.Caption

in the VBA click event of the button. If need be, you would have to put the button behind another object to hide this text.

Hi jbolognini!
I have a similar issue when I open (from a global object) multiple instances of the same popup display trough parameters. Inside the display I have a vba code and a private sub MyNumericInput_change(), in order to catch a process display changing. With one popup opened, everything works fine, but when I have two or more popups opened, the vba code act wrongly.

Any help would be much appreciated 🤞🏻🤞🏻🤞🏻
 
I found a solution! :)

Syntax
Application.UnloadDisplay [Name], [AllInstances]
AllInstances – is an optional Boolean parameter that, when True, unloads all instances of the display specified by Name if multiple instances are loaded. The default value for AllInstances is True.

So, i wrote:

Application.UnloadDisplay "/::My_Popup", False

and it works now!
Obs. "/::" applies to distributed network.
 

Similar Topics

I've been working on a fairly large project for the last couple months and have come to a road block for the last week. I've spent countless...
Replies
7
Views
7,128
Hello Experts, I am trying to create a SINE Wave generator and i cannot seem to make it smoother. I have done this before but i forgot the exact...
Replies
6
Views
302
Hello all. Is there a way to upload alarm tags at the bit level to my FTView studio? I export them from my PLC thinking I will upload them to...
Replies
2
Views
411
Hello all. Many years ago I programmed an Omron PLC and HMI and I was able to control which display was being shown on the HMI from the PLC. Is...
Replies
5
Views
338
Hello all. I am trying to establish my connections in FTView Studio. Normally, after I have set up my offline tag file in communication setup I...
Replies
3
Views
657
Back
Top Bottom