Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 通过VBA将字符串数据导入ControlLogix PLC_Excel_Vba_Plc - Fatal编程技术网

Excel 通过VBA将字符串数据导入ControlLogix PLC

Excel 通过VBA将字符串数据导入ControlLogix PLC,excel,vba,plc,Excel,Vba,Plc,我正在开发一个实用程序来更新ControlLogix处理器中的某些函数标记值。这些标记是控制器范围,我目前在本地模拟器上运行程序。目标是将某些信息从Excel表的一列传输到相邻列中命名的标记,用于两条信息,一条是DINT,另一条是字符串 单击按钮后,我的VBA代码成功触发: Sub CreateTags() Dim rslinx As Long Dim messageid As String Dim Message As String Dim severityid As String Dim s

我正在开发一个实用程序来更新ControlLogix处理器中的某些函数标记值。这些标记是控制器范围,我目前在本地模拟器上运行程序。目标是将某些信息从Excel表的一列传输到相邻列中命名的标记,用于两条信息,一条是DINT,另一条是字符串

单击按钮后,我的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
Sub-CreateTags()
暗rslinx尽可能长
将messageid设置为字符串
将消息设置为字符串
Dim severityid为字符串
模糊的严重性
作为字符串的暗淡通道
rslinx=DDEInitiate(“rslinx”、“TestAE2”)
通道=CStr(rslinx)
'检查是否建立了连接
如果错误号为0,则
MsgBox“连接到主题“+频道时出错,请使用感叹号“错误”
rslinx=0'为坏连接返回假值
如果结束
如果Err.Number=0,则
MsgBox“RSLinx连接已建立。通道为”+通道,vbDialog,“成功!”
如果结束
对于i=0到550
出错时继续下一步
messageid=Sheet3.单元格(6+i,7)
severityid=Sheet3.单元(6+i,8)
消息=表3.单元格(6+i,3)
严重性=表3.单元(6+i,2)
表3.单元格(2,1)=严重性
表3.单元格(2,2)=消息
DDERSLINX,消息ID,消息
Dderslinx,严重性,严重性
接下来我
端接头
此程序运行时不会出现任何问题,此时会出现用于记录成功连接的对话框,并正确显示频道

我想知道这是否是不兼容数据类型的问题(因此在顶部使用类型声明)


我对VBA和ControlLogix处理器都是新手。

DDEPoke
中,我认为需要指定一个范围作为数据,例如
DDEPoke rslinx、messageid、Sheet3.Cells(2,2)
。您也没有在代码结束时终止连接(
Application.DDETerminate rslinx
)嗯。。所以我想有必要为给定标签的每个小节定义一个范围?我特别想到了字符串,其中RSLogix中有一个数组,用于ASCII中的每个字符。谢谢你的想法,克里斯。在
DDEPoke
中,我认为你需要指定一个范围作为数据,例如
DDEPoke rslinx,messageid,Sheet3.Cells(2,2)
。您也没有在代码结束时终止连接(
Application.DDETerminate rslinx
)嗯。。所以我想有必要为给定标签的每个小节定义一个范围?我特别想到了字符串,其中RSLogix中有一个数组,用于ASCII中的每个字符。谢谢你的想法,克里斯。