Rob 7 Collins Posted June 1, 2005 Posted June 1, 2005 the other day I wrote 1500 lines of code to facilitate some rather simple-seeming search functionality... you can imagine just how buggy it is. The idea is it should give the user the basic ability to find records across mutliple tables, matching any field: there are two text boxes for search criteria, on for "Any of" and one for "All of". The first thing I do is "decrypt" the search strings to seperate bare words or quoted phrases into different, reference records. This script, which looks so plain it's hard to see what I've done wrong, is failing. It correctly creates the record for the first bare word or phrase... but then for some reason it fails to recurse!? script: decrypt.Any.search.field If [ not IsEmpty ( sessLayout.Search.Fields::AnyOf.Text ) ] If [ IsEmpty ( Get ( ScriptParameter ) ) ] Perform Script [ "decrypt.Any.search.field" ; Parameter: sessLayout.Search.Fields::AnyOf.Text ] Exit Script Else If [ If ( Mod ( PatternCount ( Get ( ScriptParameter ) ; """ ) ; 2 ) = 0 ; 0 ; 1 ) ] # if the count of the quotation marks is odd .... Show Custom Dialog [ "Malformed Search Parameter" ; "blah..." ] Halt Script End If Go to Layout [ "sessUser.Search.Any" (sessUser.Search.Any)] New Record/Request Set Field [ If ( Exact ( Left ( Get ( ScriptParameter ) ; 1 ) ; """ ) ; Middle ( Get ( ScriptParameter ) ; 2 ; ( Position ( Get ( ScriptParameter ) ; """ ; 1 ; 2 ) - 2 ) ) ; LeftWords ( Get ( ScriptParameter ) ; 1 ) ) ] # If ( Exact ( Left ( Get ( ScriptParameter ) ; 1 ) ; """ ) ; # Middle ( # Get ( ScriptParameter ) ; # 2 ; # ( Position ( Get ( ScriptParameter ) ; """ ; 1 ; 2 ) - 2 ) # ) # ; # LeftWords ( Get ( ScriptParameter ) ; 1 ) # ) # # if the first word in the script parameter is a bare word, set the field with that word # if the first word begins with a quotation mark, it is a phrase, set the field to the text between this quotation mark and the next one Commit Records/Requests [ No dialog ] Perform Script [ "decrypt.Any.search.field" ; Parameter: If ( Exact ( Left ( Get ( ScriptParameter ) ; 1 ) ; """ ) ; Middle ( Get ( ScriptParameter ) ; Position ( Get ( ScriptParameter ) ; """ ; 1 ; 2 ) + 1 ; ( Length ( Get ( ScriptParameter ) ) - Position ( Get ( ScriptParameter ) ; """ ; 1 ; 2 ) ) ) ; RightWords ( Get ( ScriptParameter ) ; ( WordCount ( Get ( ScriptParameter ) ) - 1 ) ) ) # If ( Exact ( Left ( Get ( ScriptParameter ) ; 1 ) ; """ ) ; # # if the first character is a quotation mark # # then we have a phrase: # Middle ( # Get ( Script Parameter ) ; # Position ( Get ( ScriptParameter ) ; """ ; 1 ; 2 ) + 1 ; # ( Length ( Get ( ScriptParameter ) ) - Position ( Get ( ScriptParameter ) ; """ ; 1 ; 2 ) ) # ) # # otherwise we have a bare word: # ; # RightWords ( # Get ( ScriptParameter ) ; # ( WordCount ( Get ( ScriptParameter ) ) - 1 ) ) # ) # # return all the words but one, from right to left, if the first word is bare # return all the characters from just after the phrase which starts at the first word Exit Script End If End If Go to Layout [ original layout ]
Søren Dyhr Posted June 1, 2005 Posted June 1, 2005 A bit of advice must be to keep yourself off recursive scripting if you can't run it in the debugger ...it's much better to split the entire task up in smaller chunks of script, so you can eliminate them one by one as source of errors. You can do the same kind of looping with the ordinary Loop[ step! Next advice is use
Rob 7 Collins Posted June 1, 2005 Author Posted June 1, 2005 Unfortunately I can't share the file, it contains confidential information (for the school system). But I'll build an equivilant and post it as soon as I can. As for the loop and multiparameter method, I'm just starting to warm to this notion. For my entire time on this board so far, I've been against this ... it is a central programming credo to never reuse variables, and that is exactly what is going on in those return delimited key fields and script parameters. But the way FileMaker is built, it really challenges you to avoid it!
Søren Dyhr Posted June 1, 2005 Posted June 1, 2005 Allright I have a hunch of what must be bothering you, scriptparamters in a recursive script gets stacked. This means that unless you unwind is it a new set of parameters you're working on in each cycle ...you have to pass previous parameters along with the call as new parameter. But if you stayed with ordinary looping would the parameter be more predictable - thats why you need to inspect the parameters passings via the debugger. --sd
Rob 7 Collins Posted June 1, 2005 Author Posted June 1, 2005 I found it, thanks to that. --thank you! My script had two states; without a parameter, and with a parameter. Flow was like this: call the script, if parameterless recall with parameter, if parameter do work and remove work from parameter and recall. Eventually the parameter is empty because the work load is done. Then it is parameterless, and restarts. (*gulp*) A simple check before recalling in the work branch to ensure script parameter is not empty fixed it.
Recommended Posts
This topic is 7118 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