NoLegalMoves
Member
I can't figure out what is not working...
Private Function OpenRSLinx()
On Error Resume Next
'Open the connection to RSLinx
OpenRSLinx = DDEInitiate("RSLINX", "PLC15")
'Check if the connection was made
If Err.Number <> 0 Then
MsgBox "Error Connecting to topic", vbAbortRetryIgnoreExclamation, "Error"
' OpenRSLinx = 0
End If
End Function
Sub Button1_Click()
Dim i As Integer
'write to PLC15
rslinx = OpenRSLinx() 'Open connection to RSlinx
'Loop through the cells and write values to the CLX array tags
For i = 0 To 9
'Get the value from the DDE link
realdata = DDERequest(rslinx, "CLN_823L31_3101_SPT[" & i & "],L1,C1")
'If there is an error, display a message box
If TypeName(realdata) = "Error" Then
If MsgBox("Error reading tag CLN_823L31_3101_SPT[" & i & "]. " & _
"Continue with read?", vbYesNo + vbExclamation, _
"Error") = vbNo Then Exit For
Else
'No error, place data in CLX
Cells(i, 2) = realdata
End If
Next i
'Terminate the DDE connection
DDETerminate rslinx
End Sub
Private Function OpenRSLinx()
On Error Resume Next
'Open the connection to RSLinx
OpenRSLinx = DDEInitiate("RSLINX", "PLC15")
'Check if the connection was made
If Err.Number <> 0 Then
MsgBox "Error Connecting to topic", vbAbortRetryIgnoreExclamation, "Error"
' OpenRSLinx = 0
End If
End Function
Sub Button1_Click()
Dim i As Integer
'write to PLC15
rslinx = OpenRSLinx() 'Open connection to RSlinx
'Loop through the cells and write values to the CLX array tags
For i = 0 To 9
'Get the value from the DDE link
realdata = DDERequest(rslinx, "CLN_823L31_3101_SPT[" & i & "],L1,C1")
'If there is an error, display a message box
If TypeName(realdata) = "Error" Then
If MsgBox("Error reading tag CLN_823L31_3101_SPT[" & i & "]. " & _
"Continue with read?", vbYesNo + vbExclamation, _
"Error") = vbNo Then Exit For
Else
'No error, place data in CLX
Cells(i, 2) = realdata
End If
Next i
'Terminate the DDE connection
DDETerminate rslinx
End Sub