dbh6
Lifetime Supporting Member
I'am using VBA code in FT View SE software. Ok just to put it out there I have no experience with VBA, but i was able to compile this code from using AB's Knowledge. Here is the brief summary of the code, Their is an HMI tag of boolean type that I created called "ControlNode". Now the the fname is point to a text file in the C folder and then "exits" wich is of type boolean uses the function FileThere() to see of the specified text file called "test" is in that folder. If the Text file called "test" which is a .txt file is in that folder then, the VBA code writes a 1 to the HMI tag that i created "ControlNode". If the text file is not their then the VBA code will write a 0 to the "ControlNode".
I tested this by putting a numeric display and linking it to the "ControlNode" and it works, however if you noticed at the beginning of the VBA code i have this VBA code called when "Sub Display_AnimationStart()" which is basically when the display is called in my case the main display, and thats when it runs the VBA code only at the start of the animation, but i'm tryin to make it so not on animation start, but during the whole time the runtime is running, i tried numerous things, but hit a road block, because i don't have experience with VBA. So i posted the code below, and if you can help me with that i would appreciate it.Also of you want to modify and post the code feel free to do so because again i may already have some unnecessary code in their.
Code is below
Option Explicit
'Global declarations
Public MyTagGroup As TagGroup
Sub Display_AnimationStart()
Dim fname As String
Dim tagValue As Tag
Dim exists As Boolean
fname = "C:\Installs\test.txt"
exists = FileThere(fname)
If MyTagGroup Is Nothing Then
'Create a tag group based on the Area that the Display is located in
Set MyTagGroup = Application.CreateTagGroup(Me.AreaName)
'Add tags to tag group
'HMI Tag Example 1 – system tag
MyTagGroup.Add "ControlNode"
End If
Dim HMITestTag As Tag
Dim DirReFactoryTalkActivationsg As Tag
Dim SystemSecondTagValue As Integer
Dim SystemSecondTagHighEU As Integer
Dim SystemSecondTagLowEU As Integer
Dim ErrorCatch As Integer ' Used to determine where error occured
On Error GoTo ErrorTrap
ErrorCatch = 1
Set HMITestTag = MyTagGroup.Item("ControlNode")
'Add one to current tag value and write back to tag
HMITestTag.Value = exists
ErrorTrap:
'Log a diagnostic message using the SystemLogModule.bas wrapper module
Set MyTagGroup = Nothing
End Sub
Function FileThere(FileName As String) As Boolean
If (Dir(FileName) = "") Then
FileThere = False
Else:
FileThere = True
End If
End Function
Private Sub Display_BeforeAnimationStop()
'Destroy tag group
Set MyTagGroup = Nothing
End Sub
Private Sub Group1_Click()
End Sub
Private Sub NumericDisplay4_Change()
End Sub
Private Sub NumericDisplay5_Change()
Dim fname As String
Dim tagValue As Tag
Dim exists As Boolean
fname = "C:\Installs\test.txt"
exists = FileThere(fname)
If MyTagGroup Is Nothing Then
'Create a tag group based on the Area that the Display is located in
Set MyTagGroup = Application.CreateTagGroup(Me.AreaName)
'Add tags to tag group
'HMI Tag Example 1 – system tag
MyTagGroup.Add "ControlNode"
End If
Dim HMITestTag As Tag
Dim DirReFactoryTalkActivationsg As Tag
Dim SystemSecondTagValue As Integer
Dim SystemSecondTagHighEU As Integer
Dim SystemSecondTagLowEU As Integer
Dim ErrorCatch As Integer ' Used to determine where error occured
On Error GoTo ErrorTrap
ErrorCatch = 1
Set HMITestTag = MyTagGroup.Item("ControlNode")
'Add one to current tag value and write back to tag
HMITestTag.Value = exists
ErrorTrap:
'Log a diagnostic message using the SystemLogModule.bas wrapper module
Set MyTagGroup = Nothing
End Sub
I tested this by putting a numeric display and linking it to the "ControlNode" and it works, however if you noticed at the beginning of the VBA code i have this VBA code called when "Sub Display_AnimationStart()" which is basically when the display is called in my case the main display, and thats when it runs the VBA code only at the start of the animation, but i'm tryin to make it so not on animation start, but during the whole time the runtime is running, i tried numerous things, but hit a road block, because i don't have experience with VBA. So i posted the code below, and if you can help me with that i would appreciate it.Also of you want to modify and post the code feel free to do so because again i may already have some unnecessary code in their.
Code is below
Option Explicit
'Global declarations
Public MyTagGroup As TagGroup
Sub Display_AnimationStart()
Dim fname As String
Dim tagValue As Tag
Dim exists As Boolean
fname = "C:\Installs\test.txt"
exists = FileThere(fname)
If MyTagGroup Is Nothing Then
'Create a tag group based on the Area that the Display is located in
Set MyTagGroup = Application.CreateTagGroup(Me.AreaName)
'Add tags to tag group
'HMI Tag Example 1 – system tag
MyTagGroup.Add "ControlNode"
End If
Dim HMITestTag As Tag
Dim DirReFactoryTalkActivationsg As Tag
Dim SystemSecondTagValue As Integer
Dim SystemSecondTagHighEU As Integer
Dim SystemSecondTagLowEU As Integer
Dim ErrorCatch As Integer ' Used to determine where error occured
On Error GoTo ErrorTrap
ErrorCatch = 1
Set HMITestTag = MyTagGroup.Item("ControlNode")
'Add one to current tag value and write back to tag
HMITestTag.Value = exists
ErrorTrap:
'Log a diagnostic message using the SystemLogModule.bas wrapper module
Set MyTagGroup = Nothing
End Sub
Function FileThere(FileName As String) As Boolean
If (Dir(FileName) = "") Then
FileThere = False
Else:
FileThere = True
End If
End Function
Private Sub Display_BeforeAnimationStop()
'Destroy tag group
Set MyTagGroup = Nothing
End Sub
Private Sub Group1_Click()
End Sub
Private Sub NumericDisplay4_Change()
End Sub
Private Sub NumericDisplay5_Change()
Dim fname As String
Dim tagValue As Tag
Dim exists As Boolean
fname = "C:\Installs\test.txt"
exists = FileThere(fname)
If MyTagGroup Is Nothing Then
'Create a tag group based on the Area that the Display is located in
Set MyTagGroup = Application.CreateTagGroup(Me.AreaName)
'Add tags to tag group
'HMI Tag Example 1 – system tag
MyTagGroup.Add "ControlNode"
End If
Dim HMITestTag As Tag
Dim DirReFactoryTalkActivationsg As Tag
Dim SystemSecondTagValue As Integer
Dim SystemSecondTagHighEU As Integer
Dim SystemSecondTagLowEU As Integer
Dim ErrorCatch As Integer ' Used to determine where error occured
On Error GoTo ErrorTrap
ErrorCatch = 1
Set HMITestTag = MyTagGroup.Item("ControlNode")
'Add one to current tag value and write back to tag
HMITestTag.Value = exists
ErrorTrap:
'Log a diagnostic message using the SystemLogModule.bas wrapper module
Set MyTagGroup = Nothing
End Sub