繼續學習wincc下VBA程式設計,這一篇練習批次修改變數的連線地址,就使用前面一篇建立的10個變數,假設這些變數的地址都是有規律的。
新建下面的指令碼:
Sub ChangeTagAddress()
Dim hmigo As hmigo
Dim strTagName As String
Dim i As Integer
Set hmigo = New hmigo
For i = 1 To 10
strTagName = "Real" & CStr(i)
strAddress = "DB2.DD" & CStr((i - 1) * 4)
hmigo.GetTag strTagName
hmigo.TagS7S5Address = strAddress
hmigo.CommitTag
Next
Set hmigo = Nothing
End Sub
上面的指令碼將REAL1至REAL10連線PLC的地址批次進行修改。