示例:写入标签

本示例阐述了如何写入属于 TagGroup 对象的标签。
由第一个子程序创建 TagGroup 对象,将标签添加到其中并激活 TagGroup Note,执行标签写操作不必激活标签组合。在这里显示出来仅为与其他示例相一致。
第二个子程序将值写入 TagGroup 中的标签。
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
提供反馈
对本文档有问题或反馈吗? 请在这里提交您的反馈
Normal