nsdodgers Posted September 27, 2019 Share Posted September 27, 2019 Hello, I'm working on a script to convert a list of numbers into a user friendly range of numbers. For example, here's a list of numbers 21 22 23 24 25 31 32 33 34 35 I would like it to set a field with: 21-25,31-35 I have a script that can easily deal with the first half, but I am struggling to make it work with multiple ranges. Set Variable [ $counter; Value:1 ] Set Variable [ $first; Value:GetValue ( range reverse::test unit numbers; $counter)] Set Variable [ $last; Value:$first ] Loop Set Variable [ $last; Value:$last+1 ] Set Variable [ $counter; Value:$counter + 1 ] Exit Loop If [ $last ≠ GetValue ( range reverse::test unit numbers; $counter) ] End Loop Set Field [ range reverse::range result; $first & "-" & $last-1 ] Thank you for the help Link to comment Share on other sites More sharing options...
comment Posted September 28, 2019 Share Posted September 28, 2019 I wrote a custom function that does this (and a bit more). Scripting it is slightly easier - try: Set Variable [ $values; Value:YourTable::ListOfValues ] Loop Set Variable [ $i; Value:$i + 1 ] Exit Loop If [ $i > ValueCount ( $values ) ] Set Variable [ $thisValue; Value:GetValue ( $values ; $i ) ] # TEST AGAINST PREVIOUS VALUE If [ GetValue ( $values ; $i - 1 ) ≠ $thisValue - 1 # START A NEW RANGE Set Variable [ $startValue; Value:$thisValue ] End If # TEST AGAINST NEXT VALUE If [ $thisValue + 1 ≠ GetValue ( $values ; $i + 1 ) ] # END THIS RANGE Set Variable [ $result; Value:List ( $result; If ( $startValue = $thisValue ; $thisValue ; $startValue & "-" & $thisValue ) )] End If End Loop Set Field [ YourTable::Result; Substitute ( $result ; ¶ ; ", " ) ] Commit Records/Requests 1 Link to comment Share on other sites More sharing options...
nsdodgers Posted September 28, 2019 Author Share Posted September 28, 2019 Perfection again, comment Link to comment Share on other sites More sharing options...
Recommended Posts
This topic is 1670 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now