Форум АСУ в Україні
http://asu.in.ua/

Використання змінних Runtime zenon у VBA
http://asu.in.ua/viewtopic.php?f=123&t=1976
Сторінка 1 з 1

Автор:  san [ 16 січня 2018, 22:37 ]
Тема повідомлення:  Використання змінних Runtime zenon у VBA

В хелпі є деяка інфа Manual -> Programming Interfaces -> Macro list -> Basics -> Functionality of online variables
Значення змінних в реальному часі можуть бути не доступні, так як не використовуються на графіці в алармах і т.п. Тому якщо звертатися до їх значення через відповідні об'єкти може виникнути помилка. Для коректного використання в рантайм значень змінних зенона необхідно їх спочатку добавити в контейнер OnlineVariables
Деталі в хелпі - Manual -> Programming Interfaces -> Objectmodel -> OnlineVariables
Цитата:
This collection contains the single objects OnlineVariable. An online variable is an object, in which control system variables are linked, which on being initialized or changed execute a VBA event. In this VBA event user defined actions can be defined.The usage of online variables is recommended for the reading of variable values, as all variables linked to the online variable can be ordered with one action. This enhances the performance.An online variable can be compared to a container or – even better – a Screen of the control system without display. In such a Screen of the control system also all values are ordered from the driver when the Screen is opened.

Dim WithEvents zOLV As OnlineVariable
Const strOLV As String = "MyOnlineVariableContainer"

'initialize event on runtime startup
Private Sub Project_Active()
'get object if already exists
Set zOLV = thisProject.OnlineVariables.Item(strOLV)
If zOLV Is Nothing Then
'if not exitst, create a new OnlineVariable container
Set zOLV = thisProject.OnlineVariables.CreateOnlineVariables(strOLV)
'add variables to the container
zOLV.Add "Variable1"
zOLV.Add "Variable2"
zOLV.Add "Variable3"
End If
'activate 'VariableChange' event
zOLV.Define
End Sub

'event is fired when a variable value changes
Private Sub zOLV_VariableChange(ByVal obVar As IVariable)
Dim vValue As Variant
vValue = obVar.Value
'ignore error values (i.e. on startup)
If IsError(vValue) Then Exit Sub
D ebug.Print obVar.Name & " = " & vValue
End Sub

'release objects on closing the runtime
Private Sub Project_Inactive()
'deactivate 'VariableChange' event
If Not zOLV Is Nothing Then zOLV.Undefine
Set zOLV = Nothing
End Sub

Сторінка 1 з 1 Часовий пояс UTC + 2 годин [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/