Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Number Range to List

Featured Replies

Has anyone seen a calc or custom function for converting a number range into a return separated list?

1-4 =

1

2

3

4

See:

http://fmforums.com/forum/showtopic.php?tid/191513/post/274473/#274473

See http://www.briandunning.com/cf/14

...custom function for converting a number range into a return separated list?

What about this one ?

Range ( values )

Let([

sep = Filter ( values ; " -/|_*to" ) ;

start = GetAsNumber ( GetValue ( Substitute ( values ; sep ; ¶ ) ; 1 ) ) ;

stop = GetAsNumber ( GetValue ( Substitute ( values ; sep ; ¶ ) ; 2 ) )

];

Case(

stop - start ≥ 10000; "error" ;

start < stop ; start & ¶ & Range ( start + 1 & ¶ & stop );

start = stop ; stop

)

)

Note: values can be proposed in various ways, like:

1 to 4

1 4

1-4 ; 1 - 4

1/4 ; 1 / 4

14 ; 1 4

1|4 ; 1 | 4

1_4 ; 1 _ 4

1*4 ; 1 * 4

but must be both positive.

So this: Range ( "20 to 25" ) gives:

20

21

22

23

24

25

The CF can't handle range of more than 9999 values.

  • Author

Thanks guys this works really well. Now can I take it one step further.

I would like the user to be able to type a range as well as individual numbers.

2-6, 8,11, 22-26

I need a CF:

1. return separate the list (sub "," ; "¶")

2-6

8

11

22-26

2. run through the list. I would assume 'MiddleValue'

3. if value contains "-" use 'EnumerateRange' else append to result

Recursive eludes me, any help is appreciated.

I don't think this is a good method for data entry - too much room for user error. It would be better IMHO to enter the data into separate fields and records.

However, if you prefer, you can try it this way:

MultiRangeCF.fp7.zip

  • Author

Thanks Comment, that is exactly it.

As for entry I agree with you, but this is for printing pages so it is temporary data.

Thanks Again!

  • Author

hi Comment,

the left and right words had to be converted to numbers to work properly, I found this out when I tried "5-18"

-=-=-=-=-=-=-

MultiEnumerate

Let ( [

values = Substitute ( input ; [ "," ; ¶ ] ; [ "-" ; " " ] ) ;

countValues = ValueCount ( values ) ;

this = GetValue ( values ; 1 )

] ;

Case ( WordCount ( this ) > 1 ; Enumerate ( GetAsNumber ( LeftWords ( this ; 1 ) ) ; GetAsNumber ( RightWords ( this; 1 ) ) ) ; Trim ( this ) )

&

Case ( countValues > 1 ; ¶ & MultiEnumerate ( RightValues ( values ; countValues - 1 ) ) )

)

//MultiEnumerate ( input )

-=-=-=-=-=

Actually, the fault is with the Enumerate () function, you should make the change there:


start & Case ( GetAsNumber (start) < GetAsNumber (end) ; ¶ & Enumerate ( start + 1 ; end ) )

Originally, when I wrote the Enumerate() function, the possibility of parameters being text never came up.

Create an account or sign in to comment

Important Information

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

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.