VBA Global Routines

jon_wootton

Member
Join Date
Sep 2008
Location
Sacramento
Posts
4
I am using VBA code to implement a confirmation for device commands in factory talk SE. I want to have a public routine I can call from any display to perform the confirmation.

The AB knowledgebase suggested creating a screen that is called upon startup with the parameters /ZA to cache the display and run it at runtime. I have declared the Public Routine in this display but when I click one of my button with the Call to the subroutine I get a failure.

The failure is that the routine being called has not been declared. Is there a way for code in graphics to call routines in other graphics or do I need to declare the subroutine in each graphic I want to use it in?
 
You need to explicitly call public functions on shared displays.

Assume your "HiddenDisplay" is your 'VBA' code display, and "MakeCoffee" is the Public function to call.

From the "Operator display, make a button, exposed to VBA.

In the VBA Code for that button, do something like this:
Code:
   Private Sub MyButton_Press()
   
      ' Get list of currently loaded displays.
      Dim LDS as Displays
      Set LDS = LoadedDisplays
   
      ' Call routine on hidden display:
      LDS.Item("HiddenDisplay").MakeCoffee
   
   End Sub

NOTE!
FactoryTalk View SE (CPR9) DOES NOT PROPERLY HANDLE PASSING PARAMETERS BETWEEN CALLS TO OTHER DISPLAY WINDOWS.

If you need this functionality, you are essentially screwed. Worked fine up to Vers. 5, CPR9, but now is iffy at best, and non-functional in general.
 
Last edited:
Type Mismatch

I added the code you suggested but when it came to the 'LDS.Item("HiddenDisplay").MakeCoffee' part my "MakeCoffee" procedure did not appear in the drop down list. I typed in my procedure with the argument anyway and when I ran the code I got a type mismatch for the display.
Not surprising since it was not in the drop down list for that screen. Is there something I need to do in my "HiddenDisplay" to add the initialise the procedure and add it to the list?
 
Make sure that all routines you call are declared as either Public or just Sub for one.

Sub MakeCoffee()

End Sub

or
Public Sub MakeCoffee()

End Sub

Part of that, means do not have any "Option Private" instructions in either display window.

Secondly, the drop down list will probably not appear in the editor, as you are trying to dynamically call a sub by name from the named display in the dynamically created list of open displays.

Also, are you calling a function or a sub?
 
I am calling a subroutine that displays a message box and performs an action according to the operator response. The action is to manipulate the value component of a numeric input field that the PLC tag is directly tied into.
 
jon_wootton said:
I am calling a subroutine that displays a message box and performs an action according to the operator response. The action is to manipulate the value component of a numeric input field that the PLC tag is directly tied into.

That may be an issue, With 5.0, passing parameters back and forth at all is bound to fail, as is returning values from one screen to another.
 
So it sounds like I am doomed to repeating the public routine for each display I want to call it from? Disappointing, thanks for your help though, very useful.
 
jon_wootton said:
So it sounds like I am doomed to repeating the public routine for each display I want to call it from? Disappointing, thanks for your help though, very useful.

Yes, if you are trying to pass anything back and forth, or return.

In my investigations (and it it mega frustrating, but no solution is forthcoming from Rockwell), passed parameters and return values between separate .GFX displays will work properly only when debugging VBA Code. When the application ramps up to full speed (non-debug mode), all objects are passed as NULL's (or 'Nothings' in VBA Terms).

I've had limited success with using VBA forms, but that is exceptionally dangerous in View SE unless you jump through hoops to ensure that they don't lock up the VBA subsystem or even all operator inputs.
 
Adding a note here, as I've just had a thought (Hey, it happens once in a while!)

To pass parameters to a Sub (or Function) on another form, it might be possible to try passing them explicitly 'ByVal', and maybe that would work on FTView SE 5.x

(on hidden_window):

Public Sub MakeCoffee(ByVal CoffeeType as Int)
...
End Sub

I haven't tried it yet, but I might go ahead and see if that would work properly sometime next week, if I can remember.

Edit again -

If that works, then perhaps returning (if needed) a value would also work, if passed explicitly as 'ByRef'...

Sub Syntax:

Public Sub MakeCoffee(ByVal CoffeeType as Int, ByRef Success as Boolean)

End Sub

Function Syntax:

Public Function MakeCoffee(ByVal CoffeeType as Int) as Boolean

MakeCoffee = True

End Function
 
Last edited:

Similar Topics

Hello guys, can anyone help me with FactoryTalk View Studio. I need to use a Global Object that contains VBA Macros in different displays, but it...
Replies
1
Views
1,677
Good day all, I'm making a Transmitter global object for my displays in Factorytalk View SE and was attemping to use VBA to Replace the...
Replies
0
Views
2,402
Hi All, I'm working with 12 or so global objects I created, that are temperature displays (basic vertical gauge). Each has several parameters...
Replies
0
Views
2,850
I have a global object that is a group of a series of objects one of which is a button. The push of the button needs to execute a VB script based...
Replies
0
Views
4,697
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...
Replies
6
Views
17,373
Back
Top Bottom