Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×
The Claris Museum: The Vault of FileMaker Antiquities at Claris Engage 2025! ×

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

Recommended Posts

Posted

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

)
Posted

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"
Posted

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

)
Posted

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

This topic is 4058 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.