rivet Posted December 10, 2013 Posted December 10, 2013 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 )
eos Posted December 10, 2013 Posted December 10, 2013 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"
rivet Posted December 10, 2013 Author Posted December 10, 2013 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 )
eos Posted December 10, 2013 Posted December 10, 2013 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.)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now