Visual Basic With FactoryTalk View Studio Site Edition

joelryan22

Member
Join Date
Aug 2017
Location
Ohio
Posts
13
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?

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!
 
If you step through your code, where does it jump to Err_Handler?

The only possible problem i see is with
Code:
Set Dif_Test_A = mytagGroup.Item("Dif_Test_A")

Do you have a tag named "Dif_Test_A"? If not it will go to the error handler.

Comment this line (and the next one) and try your code again.
 
If you step through your code, where does it jump to Err_Handler?

The only possible problem i see is with
Code:
Set Dif_Test_A = mytagGroup.Item("Dif_Test_A")

Do you have a tag named "Dif_Test_A"? If not it will go to the error handler.

Comment this line (and the next one) and try your code again.

Thanks Crawler,

I commented out my error handler instead and debugged my code using the built in debugger. I was mimicking an example from the FactoryTalk user manual and followed it a bit too close šŸ™ƒ. The error was in the line you mentioned!
 

Similar Topics

I'm just trying to load from a text file into a string. I don't get why this doesn't work. Function LoadFile(FileName As String) As String()...
Replies
0
Views
1,548
I have a small application where i want to use a numeric input to change the tags for another numeric input i am referring to dynamically. I am...
Replies
6
Views
2,667
from visual basic I am trying to write to a variable in factorytalk called alarm, this variable is of binary type, should not be a problem but I...
Replies
4
Views
4,049
Good morning! I've run into a stopping point with a Visual Basic task on a View Studio SE project and was wondering if anyone could point me in...
Replies
3
Views
26,946
Dear experts, I am want to program RS view32 with help of Microsoft visual basic (visual basic editor). But how to start I don't know,please...
Replies
10
Views
2,379
Back
Top Bottom