Convert AB RSLogix tags

dkintz

New Member
Joined
Jan 19, 2018
Messages
11
Good morning!

I have a need to convert Allen Bradley RSLogix tags from one format to another. I can save the tags into a .csv and open in Excel. I would like to write a macro to convert them into another format. Here's an example:

Old format: New Format:

N11:0/0 N11[0].0
N11:0/1 N11[0].1
N11:0/2 N11[0].2

And so on..... basically take everything after the colon and reformat it.

Some tags would not have anything after the dash and would be in the form:

N31:0 to N31[0]
N31:1 N31[1]

And so on......
 
In case the others don't return using built-in functions...

I think this UDF should handle the examples you've presented.
Code:
Public Function RSLogic(str As String) As String

    Dim newStr As String, ray As Variant
    Dim x As Integer, plcStr As String, workStr As String
    
    If Left(str, 3) = "::[" Then
        x = InStr(1, str, "]")
        If x Then
            plcStr = Left(str, x)
            workStr = Mid(str, x + 1)
        End If
    Else
        workStr = str
    End If
    
    If InStr(1, workStr, ":") And InStr(1, workStr, "/") Then
        ray = Split(Replace(workStr, ":", "/"), "/")
        newStr = plcStr & ray(0) & "[" & ray(1) & "]." & ray(2)
    ElseIf InStr(1, workStr, ":") And InStr(1, workStr, "/") = 0 Then
        ray = Split(workStr, ":")
        newStr = plcStr & ray(0) & "[" & ray(1) & "]"
    Else
        newStr = plcStr & workStr
    End If
    
    RSLogic = newStr
    
End Function

Holy smokes! This works wonderfully with all the forms. I was trying yesterday to get the LEFT and MID to work and I couldn't quite get the form right. Thank you so much for this!
 
Upvote 0

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
@ Rick

I must be missing something, these results look the same to me, have you shown the wrong example?

::[PLC1]N101[4].11 <~~ yours
::[PLC1]N101[4].11 <~~ mine
 
Upvote 0
@ Rick

I must be missing something, these results look the same to me, have you shown the wrong example?

::[PLC1]N101[4].11 <~~ yours
::[PLC1]N101[4].11 <~~ mine
No, you are not missing anything... I am not sure what I did earlier that (I thought) showed me your UDF returning the wrong value, but you are right... your code does, in fact, return the correct value for it. Sorry for the false alarm. At least my claim to a more compact function is still true.:lol:
 
Last edited:
Upvote 0
Your function would not handle this input text correctly...

::[PLC1]N101:4/11

which I extrapolated from the original examples posted by the OP. Here is a much shorter function (note the slight function name change) that returns the same values as your function except that it also correctly handles the above input text as well...
Code:
Function RSLogix(S As String) As String
  Dim Begin As String
  If Not S Like "*/*" Then S = S & "]"
  If S Like "::*" Then
    Begin = Left(S, InStr(S, "]"))
    S = Mid(S, InStr(S, "]") + 1)
  End If
  S = Replace(Replace(S, ":", "["), "/", "].")
  RSLogix = Begin & S
End Function

I will try this function. It turns out you are correct. The one from NoSparks runs into problems when the address changes to a 3 digit number (i.e. if the N11 becomes an N124, etc).

So, there are multiple solutions in play here which may need two different functions?
One which will handle the forms:
N11:0/0 N11[0].0
N11:0/1 N11[0].1
N11:0/2 N11[0].2
 
Upvote 0
No doubt about your code being shorter.

I did a little ladder logic with AB PLC-5's about 25-30 years ago.
Knowing there are Timers, Counters, Status, Bits and more and not knowing the addressing requirements of today,
it would surprise me if the OP's situation is not a 'work in progress' that will require more adjustments.
For me the longer version is easier to visualize.
 
Upvote 0
I did a little ladder logic with AB PLC-5's about 25-30 years ago.
Knowing there are Timers, Counters, Status, Bits and more and not knowing the addressing requirements of today,
it would surprise me if the OP's situation is not a 'work in progress' that will require more adjustments.
For me the longer version is easier to visualize.
I have no idea what ladder logic or RSLogix are... I never heard of either before.


For me the longer version is easier to visualize.
Interesting... for me, the shorter code is easier to follow (although that may be because I wrote it, so I am familiar with the "flow" of it all).
 
Upvote 0
Your function would not handle this input text correctly...

::[PLC1]N101:4/11

which I extrapolated from the original examples posted by the OP. Here is a much shorter function (note the slight function name change) that returns the same values as your function except that it also correctly handles the above input text as well...
Code:
Function RSLogix(S As String) As String
  Dim Begin As String
  If Not S Like "*/*" Then S = S & "]"
  If S Like "::*" Then
    Begin = Left(S, InStr(S, "]"))
    S = Mid(S, InStr(S, "]") + 1)
  End If
  S = Replace(Replace(S, ":", "["), "/", "].")
  RSLogix = Begin & S
End Function

I will try this function. It turns out you are correct. The one from NoSparks runs into problems when the "N" address changes to a 3 digit number (i.e. if the N11 becomes an N124, etc).

So, there are multiple solutions necessary which may need two different functions?
One which will handle the forms:
N11:0/0 to N11[0].0 etc
N11:32 to N11[32] etc
N121:0/0 to N121[0].0 etc
N121:32 to N121[32] etc

and one which will handle all those forms with an additional form at the begining:
::[anylengthname]N11:0/0 to
::[anylengthname]N11[0].0 etc
::[anylengthname]N11:32 to ::[anylengthname]N11[32] etc
::[anylengthname]N121:0/0 to ::[anylengthname]N121[0].0 etc
::[anylengthname]N121:32 to ::[anylengthname]N121[32] etc

I tried the SEARCH function with no success (i.e search for the "]" and run the NoSparks type method after that. Still struggling but learning allot, thanks!
 
Upvote 0
Thank you NoSparks. Since you know the ladder logic code I am talking about, I will respond to you directly.

The old RSLogix 500 forms are:
N11:0/0 etc.
N11:32 etc.
N121:0/0 etc.
N121:32 etc.
The same addresses for RSLogix 5000 are in the form:
N11[0].0 etc.
N11[32] etc.
N121[0].0 etc.
N121[32] etc.
Basically, the difference is that RSLogix 500 uses registers and RSLogix 5000 uses arrays.


The second function needed is for integration with the HMI screens. The addresses then have the location of the name of the PLC attached at the beginning of the address in a “::[Name]” format. The name can be any length. The “N11” can be 1-3 digits. Anything after the colon can be 1-3 digits. After the “/” can be 0-15.

::[anylengthname]N11:0/0 to ::[anylengthname]N11[0].0 etc.
::[anylengthname]N11:32 to ::[anylengthname]N11[32] etc.
::[anylengthname]N121:0/0 to ::[anylengthname]N121[0].0 etc.
::[anylengthname]N121:32 to ::[anylengthname]N121[32] etc.
 
Upvote 0
I will try this function.

So, there are multiple solutions necessary which may need two different functions?
I believe the one UDF that I posted will correctly handle all of the formats that you posted. Give it a try and let me know whether it works or not (if not, post example of what didn't work).
 
Upvote 0
@ dkintz

You've lost me with post #18 as both Rick and my functions convert your examples as requested.
The addresses then have the location of the name of the PLC attached at the beginning of the address in a “::[Name]” format. The name can be any length. The “N11” can be 1-3 digits. Anything after the colon can be 1-3 digits. After the “/” can be 0-15.

::[anylengthname]N11:0/0 to ::[anylengthname]N11[0].0 etc.
::[anylengthname]N11:32 to ::[anylengthname]N11[32] etc.
::[anylengthname]N121:0/0 to ::[anylengthname]N121[0].0 etc.
::[anylengthname]N121:32 to ::[anylengthname]N121[32] etc.
You say The addresses then have, but these examples would indicate the concatenation done prior to the format conversion.
What exactly is the issue?

It would be advantages to share your Excel file, redacted, of course.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top