joelryan22
Member
Hello,
Im trying to learn how to use VBA with factorytalk view so i can later design displays using tags from PLCs and im having some trouble completing a basic exercise to increase my fundamental understanding.
I have 3 Tags
Dif_Test (Type: Analog, Data Source: Memory, Initial Value: 0)
Ex_Tag1 (Type: Analog, Data Source: Memory, Initial Value: 1)
Ex_Tag2 (Type: Analog, Data Source: Memory, Initial Value: 3)
I want Ex_Tag1 to be subtracted from Ex_Tag2 and stored into Dif_Test when i click on the Ex_Tag1 text. I have all 3 displayed on a display screen. When i click on Ex_Tag1 Nothing happens. Could anyone tell me my error in logic/code?
Again, Thanks for any help!
Im trying to learn how to use VBA with factorytalk view so i can later design displays using tags from PLCs and im having some trouble completing a basic exercise to increase my fundamental understanding.
I have 3 Tags
Dif_Test (Type: Analog, Data Source: Memory, Initial Value: 0)
Ex_Tag1 (Type: Analog, Data Source: Memory, Initial Value: 1)
Ex_Tag2 (Type: Analog, Data Source: Memory, Initial Value: 3)
I want Ex_Tag1 to be subtracted from Ex_Tag2 and stored into Dif_Test when i click on the Ex_Tag1 text. I have all 3 displayed on a display screen. When i click on Ex_Tag1 Nothing happens. Could anyone tell me my error in logic/code?
Code:
Option Explicit
Public mytagGroup As TagGroup
-------------------------------------------------------------------------------------------
Public Sub Display_Activate()
On Error GoTo Err_Handler
If mytagGroup Is Nothing Then
Set mytagGroup = Application.CreateTagGroup(Me.AreaName)
mytagGroup.Add "Ex_Tag1"
mytagGroup.Add "Ex_Tag2"
mytagGroup.Add "Dif_Test"
End If
Exit Sub
Err_Handler:
LogDiagnosticsMessage "Error in DisplayAnimationStart", ftDiagSeverityError, ftDiagAudienceOperator
End Sub
-------------------------------------------------------------------------------------------
Public Sub Text21_Click()
Dim Ex_Tag1_A As Tag
Dim Ex_Tag2_A As Tag
Dim Dif_Test_A As Tag
Dim Ex_Tag1_Val As Integer
Dim Ex_Tag2_Val As Integer
Dim Dif_Test_Val As Integer
On Error GoTo Err_Handler
Set Ex_Tag1_A = mytagGroup.Item("Ex_Tag1")
Ex_Tag1_Val = Ex_Tag1_A.Value
Set Ex_Tag2_A = mytagGroup.Item("Ex_Tag2")
Ex_Tag2_Val = Ex_Tag2_A.Value
Set Dif_Test_A = mytagGroup.Item("Dif_Test_A")
Dif_Test_Val = Dif_Test_A.Value
mytagGroup.Item("Dif_Test").Value = (Ex_Tag2_Val - Ex_Tag1_Val)
Exit Sub
Err_Handler:
LogDiagnosticsMessage "Error Determining Difference", ftDiagSeverityError, ftDiagAudienceOperator
End Sub
Again, Thanks for any help!