发表于:2006-08-21 17:41:00
2楼
下面是VBA自带的例子(对Tag进行写操作),你可以参考一下:
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