wincc 7.5SP2下VBA编程学习练习15:批量删除变量

在前面练习的基础上学习批量删除变量。

新建下面的脚本:

Sub DeleteTags()
'批量删除变量
Dim hmigo As hmigo
Dim strTagName As String
Dim i As Integer
Set hmigo = New hmigo
For i = 1 To 5
strTagName = "Real" & CStr(i)
hmigo.DeleteTag strTagName
Next
Set hmigo = Nothing
End Sub

保存,运行就会删除Real1至Real5共计5个变量。如果这些变量已经被删除了,运行脚本就会报错。

为了容错性,对上面的脚本重新编写如下,先判断要删除的变量是否存在,存在才做删除操作:

Sub DeleteTags()
'批量删除变量
Dim hmigo As hmigo
Dim strTagName As String
Dim i As Integer
Set hmigo = New hmigo
'For i = 1 To 5
' strTagName = "Real" & CStr(i)
' hmigo.DeleteTag strTagName
'Next
For i = 1 To 5
strTagName = "Real" & CStr(i)
hmigo.ListTag TAG_NAMES, Tags, strTagName
If (UBound(Tags) - LBound(Tags) + 1) > 0 Then
hmigo.DeleteTag strTagName
End If
Next
Set hmigo = Nothing
End Sub

 

posted @ 2024-11-18 12:02  来自金沙江的小鱼  阅读(6)  评论(0编辑  收藏  举报