RobertHart
Member
Hey guys. New here and have a vba question for factorytalk.
I'm trying to use vba to pull tag data and then write the data to a textbox and a textfile. I've tried to use the following example that is listed in factorytalk help, but just can't seem to make it work.
Dim WithEvents oGroup As TagGroup
Sub SetUpTagGroup()
On Error Resume Next
Err.Clear
If oGroup Is Nothing Then
Set oGroup = Application.CreateTagGroup(Me.AreaName, 500)
If Err.Number Then
LogDiagnosticsMessage "Error creating TagGroup. Error: " _
& Err.Description, ftDiagSeverityError
Exit Sub
End If
oGroup.Add "System\Second"
oGroup.Add "System\Minute"
oGroup.Active = True
End If
End Sub
Sub SetTagValue()
On Error Resume Next
Dim oTag As Tag
If Not oGroup Is Nothing Then
Set oTag = oGroup.Item("System\Second")
Err.Clear
oTag.Value = 10
' Test the Error number for the result.
Select Case Err.Number
Case 0:
' Write completed successfully... log a message
LogDiagnosticsMessage "Write to tag " & oTag.Name & " was successful."
Case tagErrorReadOnlyAccess:
MsgBox "Unable to write tag value. Client is read-only."
Case tagErrorWriteValue:
If oTag.LastErrorNumber = tagErrorInvalidSecurity Then
MsgBox "Unable to write tag value. The current user does not have security rights."
Else
MsgBox "Error writing tag value. Error: " & _
oTag.LastErrorString
End If
Case tagErrorOperationFailed:
MsgBox "Failed to write to tag. Error: " & Err.Description
End Select
End If
End Sub
I lose it with this piece of code, "Set oGroup = Application.CreateTagGroup(Me.AreaName, 500)".
The name of the textbox is TEXTBOX1. The name of the factorytalk view program is "Production Control System". The name of the sheet is "Laser Short Pour". No matter how I interchange these names with "Application" and "Me", I can not create the group.
I'm sure it is just a lack of understanding on my part so just a little help please.
I'm trying to use vba to pull tag data and then write the data to a textbox and a textfile. I've tried to use the following example that is listed in factorytalk help, but just can't seem to make it work.
Dim WithEvents oGroup As TagGroup
Sub SetUpTagGroup()
On Error Resume Next
Err.Clear
If oGroup Is Nothing Then
Set oGroup = Application.CreateTagGroup(Me.AreaName, 500)
If Err.Number Then
LogDiagnosticsMessage "Error creating TagGroup. Error: " _
& Err.Description, ftDiagSeverityError
Exit Sub
End If
oGroup.Add "System\Second"
oGroup.Add "System\Minute"
oGroup.Active = True
End If
End Sub
Sub SetTagValue()
On Error Resume Next
Dim oTag As Tag
If Not oGroup Is Nothing Then
Set oTag = oGroup.Item("System\Second")
Err.Clear
oTag.Value = 10
' Test the Error number for the result.
Select Case Err.Number
Case 0:
' Write completed successfully... log a message
LogDiagnosticsMessage "Write to tag " & oTag.Name & " was successful."
Case tagErrorReadOnlyAccess:
MsgBox "Unable to write tag value. Client is read-only."
Case tagErrorWriteValue:
If oTag.LastErrorNumber = tagErrorInvalidSecurity Then
MsgBox "Unable to write tag value. The current user does not have security rights."
Else
MsgBox "Error writing tag value. Error: " & _
oTag.LastErrorString
End If
Case tagErrorOperationFailed:
MsgBox "Failed to write to tag. Error: " & Err.Description
End Select
End If
End Sub
I lose it with this piece of code, "Set oGroup = Application.CreateTagGroup(Me.AreaName, 500)".
The name of the textbox is TEXTBOX1. The name of the factorytalk view program is "Production Control System". The name of the sheet is "Laser Short Pour". No matter how I interchange these names with "Application" and "Me", I can not create the group.
I'm sure it is just a lack of understanding on my part so just a little help please.