VBA To write tag values in Control logix

nchahal7

Member
Join Date
Oct 2015
Location
KItchener
Posts
13
Hi all
I am trying to write an array in PLC from my excel data base
below is code
Sub Update()

Dim Test_array_Src() As String

RSlinx = OPENRSlinx()

For x = 0 To 500
realdata = DDERequest(RSlinx, ("Source_array.Test_array_SRC_DINT[" & x & "],L1,C1"))
If TypeName(realdata) = "Error" Then
If MsgBox("Error reading tag Source_array.Test_array_SRC_DINT[" & x & "]. " & "Continue with write?", vbYesNo + vbExclamation, "error") = vbNo Then Exit For
Else
DDEPoke RSlinx, "Source_array.Test_array_SRC_DINT[" & x & "]", Cells(x + 1, 2)
End If
Next x
DDETerminate RSlinx
End Sub
Private Function OPENRSlinx()

On Error Resume Next
OPENRSlinx = DDEInitiate("RSLINX", "My_topic")
If Err.Number <> 0 Then
MsgBox "Error Connecting to topic", vbExclamation, "Error"
OPENRSlinx = 0
End If

End Function





I am getting error in finding tag , it gives error code "Realdata=Error 2023"
Please help
 
Last edited:
What is the size of the array in the controller ?

Your vba loop is from 0 to 500 - that is 501 elements, not 500
 
That should not be a problem, as i tried debugging it by going step by step but it shows error in very first step. also i got idea of this code from google, and i don't know abot what L1, C1 stands here.
may be thats where i am wrong, please advise
 
Start with something easy. Just move one data point. Not an array of 500. Once you understand that then you can expand your function.

It looks like you are copying code from various other topics and websites from several years ago. There is discussion in those threads about L1 and C1.
 
You need to learn a bit more regarding the basic steps in VBA, the code you have postet will not work, you are using tags in you code that is not anisgned

Realdata=Error 2023

No one now what Realdata is, you need to declare it first (Dim)
 
Try rewriting

realdata = DDERequest(RSlinx, ("Source_array.Test_array_SRC_DINT[" & x & "],L1,C1"))

as

realdata = DDERequest(RSlinx, "Source_array.Test_array_SRC_DINT[" & x & "],L1,C1")

I don't know if it will work, but that's the DDERequest format I am successful with.
 

Similar Topics

  • Poll
How to write a VBA in Factory Talk to read Alarm Tag from Alarm summary and open a display associated to that tag. Or open any desired display...
Replies
2
Views
7,044
Hi Guys, I am having some difficulty getting some VBA to work.My VBA is bad... I want to write a subroutine which takes 2 parameters 1. Value to...
Replies
0
Views
5,676
Hello Friends.... I am trying to read & write the PLC tags through VBA code but not getting correct syntax, i m using FTView SE 6.0 Your help will...
Replies
10
Views
8,248
This is probably a stupid question but I searched and I've read the F Manual but I still can't figure out how to read or write a tag value in VBA...
Replies
5
Views
10,057
Hi all, Trying to find an answer to what I can't believe hasn't already been asked and answered on this site or elsewhere on the interwebz. But...
Replies
10
Views
7,794
Back
Top Bottom