FTViewSE VBA - VBA variable resets value

Revnus

Member
Join Date
Aug 2019
Location
Brazil
Posts
73
I want to have two displays that uses the same VBA variable "vbaint". But when I change between them, the variable seems to reset.

How can I do it so it wont reset?

My code (on both displays):

Public vbaint as Integer

Public Sub Display_AnimationStart()
On Error GoTo ErrHandler

vbaint = vbaint + 1

Exit Sub

ErrHandler:
Application.LogDiagnosticsMessage "Error occurred in " & ThisDisplay.FullName & _
" Display_AnimationStart(). Error # " & Err.Number & ": " & Err.Description, ftDiagSeverityError
End Sub


I dont want to use HMI or PLC tags to store it, because vbaint value should be local to the runtime application of each operator.
 
You need to have all your VBA code that needs to share variables on ONE display. Each display is its entirely own instance of VBA.


Oh, and it is really really bad practice to declare a variable, and not initialize it. Always.


Another option, is to use a memory tag to maintain the state of your variable.
 
You need to have all your VBA code that needs to share variables on ONE display. Each display is its entirely own instance of VBA.


Oh, and it is really really bad practice to declare a variable, and not initialize it. Always.


Another option, is to use a memory tag to maintain the state of your variable.

Thanks for the reply. Im beginner at VBA and I have few questions:

How can I share variable on one display since they are not open always? If I was to use a third invisible display, how can I trigger to execute the line "vbaint = vbaint + 1" when I open the first two main displays?

If I assign a value to vbaint, wont the code reset the variable value, every time it executes?

I guess that memory tag you mean HMI tag. HMI tag is not desirable because the value of vbaint should be local to each runtime application. Operatos can have different runtimes with different values of vbaint.
 
That's just the thing, you can't share anything between Displays, since if a display isn't open, the code doesn't exist. RSView32 used a Global VBA model, but FTView doesn't, it uses only local, per display code.


That is why I think the best solution, would be to use a memory tag, of course, that gets complicated if you can have multiple clients open. You might have to do something like write an actual number to a file, and read it when needed.


By declaring a variable, you allocate space for it, and I do believe VBA initializes it to zero for a number, but don't count on that behavior. The first time you use it, make sure you initialize it to something (or load it from a memory tag, or read from a file, etc)


You could even read and write it to a database, with a field for the client name. Then it is just a little bit of SQL to retrieve/update.



I really hate FTView, this is something that Ignition makes a breeze, with client local tags.
 
Alternately, you can create a hidden, non-visible display on startup to 'hold' any objects you want global access to. Reference via DisplayName.MethodName.

I had a similar question years ago and the approach I mention in this post worked well enough, even though it feels a little convoluted.

-Trevor
 
Last edited:

Similar Topics

I'm begginer at VBA. What should be the correct way to check if a display is currently showing and then show another display? I tried to put this...
Replies
17
Views
8,364
I have a alarm banner A display that shows on the botton of the screen and that must shown along with any of two specific main centered displays...
Replies
2
Views
2,040
So, if I had a parameter file with #1=mytag, how could I read that parameter tag value in VBA on the popup screen opened with that parameter file...
Replies
3
Views
3,199
I am attempting to access HMI tag properties (Description, Minimum, Maximum values) to populate a numeric input. Is there a clean way to do this...
Replies
0
Views
373
Hello everyone. I'm asking for help with the following problem: in FTView SE 13.00 for the AlarmEventSummary1 object, you need to add the filter...
Replies
0
Views
599
Back
Top Bottom