Scripting in Factorylink

M

Thread Starter

marcy

I have written code for my Factorylink app, and it works. However, it only executes once.

I am trying to change an object when the value of a tag changes. Right now I have my code on the mimic run event, but it only executes when I open that mimic, and never again. Any suggestions where I should put this subroutine?
 
G

Gustavo A. Valero P.

Hi,

If you are using the real VBA in FactoryLink 7.2 or higher and want to run any script (e.g. able to change an object or show some message) based on change of tag value (at any time), this is the trick:

=============================
Dim WithEvents objMyOPCVar As Variable

Private Sub Mimic_Open()
Set objMyOPCVar = [OPCCluster:MyTagFL]
objMyOPCVar.EnableEvents = True
End Sub

Private Sub objMyOPCVar_ValueChange()
Dim NewVal as String

NewVal = objMyOPCVar.Value
x = MsgBox("The Tag has a new Value= " & NewVal, vbCritical, "Notification")

End Sub

=============================

With this, you will receive a message from Client Builder any time that "MyTagFL" tag changes AND the mimic that contains this script is OPEN.

I hope this can help you if I understood well your idea.

Best regards.

Saludos.

Gustavo A. Valero P.
BIConsulting C.A.
Valencia - Venezuela
gustavo.valero @ biconsulting. com
 
Top