Skip 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.

item position in an array

Featured Replies

I am wondering if there is a simpler solution,  (and perhaps wondering if I am stuck in the 90's)

Let ( [

target= "¶3¶";

array = 
"¶"&   "52¶47¶4¶3¶1"    & "¶"  ;

total = PatternCount ( array ; "¶" ) -1 ;
pos = Position ( array ; target ; 1 ;1 ) ;
sub = Left ( array ; pos ) ;
count =  PatternCount ( sub ; "¶" ) -1

];

count & "/" & total

)

When working with lists, ValueCount is preferable to PatternCount:

 

Let ( [
target = 3 ;
array = List ( 52 ; 47 ; 4 ; 3 ; 1 ) ;
 
total = ValueCount ( array ) ;
pos = Position ( ¶ & array & ¶ ; ¶ & target & ¶ ; 1 ; 1 ) ;
sub = Left ( array ; pos ) ;
count =  ValueCount ( sub )
] ;
count & "/" & total
)
 
results in "4/5"
  • Author

Nice and tidy, thank you! 

  • Author

FYI, the second part to this calc is to determine next or previous in array:

Let ( [

sp = "previous" ;  //Get ( ScriptParameter )
dir = Case ( sp="next" ; 1 ; sp="previous" ; -1 ) ;

target= 3;

array = List ( 52 ; 47 ; 4 ; 3 ; 1 ) ;

total = ValueCount ( array ) ;
pos = Position ( ¶ & array & ¶ ; ¶ & target & ¶ ; 1 ;1 ) ;
sub = Left ( array ; pos ) ;
count =  ValueCount ( sub ) ;

goto = 
case (
count = 1 and dir = -1 ; "" ;
count = total AND dir = 1 ; "" ;
GetValue ( array ; count+dir ) 
)

];

goto

)

You're welcome.

 

btw, FileMaker doesn't throw an OutOfBounds exception in your face, or some such stuff, if you try to access a non-existing list position (maybe internally, and it's gracefully captured …), it simply returns an empty result; otherwise you'd also have to do this check for the original calculation. So you can forego the final Case() and simply say "count + dir".

 

How are you passing the script parameters, i.e. why not use 1 and -1 from the outset? (And 0 – then it's all in one compact package.)

Create an account or sign in to comment

Important Information

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

Account

Navigation

Search

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.