我正在使用一个实用程序来更新ControlLogix处理器中的某些功能标记值。标签是控制器范围,我目前在本地模拟器上运行该程序。目标是将某些信息从Excel表的一列传输到相邻列中的标签,以获取两条信息,一条是DINT,另一条是STRING。
我的VBA代码成功触发按钮点击:
Sub CreateTags()
Dim rslinx As Long
Dim messageid As String
Dim Message As String
Dim severityid As String
Dim severity As Long
Dim channel As String
rslinx = DDEInitiate("RSLinx", "TestAE2")
channel = CStr(rslinx)
'Check if the connection was made
If Err.Number <> 0 Then
MsgBox "Error Connecting to topic" + channel, vbExclamation, "Error"
rslinx = 0 'return false value for bad conn
End If
If Err.Number = 0 Then
MsgBox "RSLinx Connection Established. Channel is " + channel, vbDialog, "Success!"
End If
For i = 0 To 550
On Error Resume Next
messageid = Sheet3.Cells(6 + i, 7)
severityid = Sheet3.Cells(6 + i, 8)
Message = Sheet3.Cells(6 + i, 3)
severity = Sheet3.Cells(6 + i, 2)
Sheet3.Cells(2, 1) = severity
Sheet3.Cells(2, 2) = Message
DDEPoke rslinx, messageid, Message
DDEPoke rslinx, severityid, severity
Next i
End Sub
此程序运行没有任何问题,并显示注意到成功连接的对话框并正确显示通道。
我想知道这可能是不兼容的数据类型问题(因此在顶部使用了类型声明。)
我是VBA和ControlLogix处理器的新手。