Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 1883 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

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

Posted

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

 

  • Like 1

This topic is 1883 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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.