innodat Posted February 4, 2012 Posted February 4, 2012 The following custom function allows for variables to receive names "on the fly" SetGlobalVariable [name; value; repetition] Parameters: name, repetition, value Evaluate(" Let( $$" & name & "[" & repetition & "] = \"" & value & "\" ; \"\" ) " ) The naming portion works fine (feed it Get(LayoutName) for example), however in the value portion, it replaces line breaks ("¶") with spaces (" ")? If you feed the function a value which contains a list, such as Raw apple Juicy mango Bad apricot it stores it as Raw apple Juicy mango Bad apricot I would like it to keep the line breaks so that I can work with each value in a flexible way (and can use strings with spaces). Any ideas on how to modify the custom function to do that?
Cliff Zhou Posted February 4, 2012 Posted February 4, 2012 Hi, I improved your function: Evaluate(" Let( $$" & name & "[" & repetition & "] = "" & Substitute( value; "¶"; "¶") & ""; "" ) ")
comment Posted February 4, 2012 Posted February 4, 2012 I would like it to keep the line breaks so that I can work with each value in a flexible way (and can use strings with spaces). Any ideas on how to modify the custom function to do that? How about = Evaluate ( "Let ( $$" & name & "[" & repetition & "] = " & Quote ( value ) & " ; "" )" )
Cliff Zhou Posted February 4, 2012 Posted February 4, 2012 How about = Evaluate ( "Let ( $$" & name & "[" & repetition & "] = " & Quote ( value ) & " ; "" )" ) It does not work. Evaluate seems to deal with any breaks as a " " except for adding a ""before it.
comment Posted February 4, 2012 Posted February 4, 2012 It works for me. How are you testing the result?
dansmith65 Posted February 4, 2012 Posted February 4, 2012 I use this function: http://fmfunctions.com/functions_display_record.php?functionId=160 It allows the datatype of the value to persist, so if your value contains a date, it does not have to be converted to text, as it will be in all the above examples.
innodat Posted February 4, 2012 Author Posted February 4, 2012 Wow, thank you all! I ended up using comment's function - works like a charm. Therefore, here's (yet another) version for memorizing and restoring tab panels - shorter than most I've seen, however it doesn't account for nested tabs. TabMemorySample.zip
comment Posted February 4, 2012 Posted February 4, 2012 It allows the datatype of the value to persist That's a good point - but see also: http://fmforums.com/forum/topic/64063-and-variables-in-custom-functions/
Cliff Zhou Posted February 5, 2012 Posted February 5, 2012 My way is ******* complex. I retested comment's funtion just now and found that I made some mistakes when I use the quote (). Evaluate(" Let( $$" & name & "[" & repetition & "] = "" & Quote( value) & ""; "" ) ")
dansmith65 Posted February 5, 2012 Posted February 5, 2012 That's a good point - but see also: http://fmforums.com/forum/topic/64063-and-variables-in-custom-functions/ Interesting conversation there, but what aspect of the conversation is relevant here? Are you referring to the scope of $ variables defined outside a script? I can't think of any issue with the custom function I linked to (unless you use a variable named $_varSetArg anywhere else in your database).
comment Posted February 5, 2012 Posted February 5, 2012 Yes, the point is that it's best to manage variables closely in order to prevent a possible collision. I would at least rewrite Shawn's function as = Let ( [ $varSetArg = value ; action = Evaluate ( "Let ( " & varName & "[" & index & "] = $varSetArg ; 0 )" ) ; $varSetArg = "" ] ; "" )
dansmith65 Posted February 5, 2012 Posted February 5, 2012 Good point. I usually use namespacing to prevent collision, but I like your method of clearing the variable when finished with it.
innodat Posted February 6, 2012 Author Posted February 6, 2012 Now I'm somewhat lost... lol For what I'm trying to achieve, the variables are never "finished". They are supposed to stay and become updated with new information if available. To me, such is the concept of memorizing tabs on each and every layout, visited and re-visited. I would claim that the global variables are not in any danger of colliding either, if the naming convention of the sample file is put to action: "$$FrontTabs_" & Get(LayoutName) I like it especially because there's no need to hard-code anything. Unlike this solution here, for example: http://sixfriedrice.com/wp/script-triggers-monitoring-and-restoring-tabs/ :)
dansmith65 Posted February 6, 2012 Posted February 6, 2012 clearing the variable when finished with it. I was referring to the $varSetArg variable in comment's last post. Regarding your sample file; it reminds me of Sticky Tabs by Jonathan Stark: http://jonathanstark...s-in-filemaker/ I've actually created my own version of a tab saving/restoring system, based off Jonathan Stark's Sticky Tabs. I use a custom function to extract the nesting structure from the LayoutObjectNames() function, then use a similar script to restore the tabs. The advantage of my method is that there is no restrictions to the naming of nested tabs. I'm planning on putting together a sample file sometime, but for now, here is the Custom Function I use: /* FrontTabPanels ( ObjectNames ) PURPOSE: Save the active tabs, and their depth in a nested tab structure. PARAMETERS: ObjectNames (text) the result of: LayoutObjectNames ( Get ( FileName ) ; Get ( LayoutName ) ) RETURNS: (text) list of values. Each value contains a number representing the depth, a tab, then the object name. DEPENDENCIES: REVISIONS: 2011-AUG-28 - Created by Dan Smith [email protected] ####################################################################################################*/ If( // this causes recursion to stop not IsEmpty( ObjectNames ) ; Let( [ // remove empty groups ObjectNames = Substitute ( ObjectNames ; "<¶>¶" ; "" ); ~current = GetValue( ObjectNames ; 1 ) ]; Case( // start group ~current = "<" ; Let( $FrontTabPanels_depth = $FrontTabPanels_depth + 1 ; "" ) ; // end group ~current = ">" ; Let( $FrontTabPanels_depth = $FrontTabPanels_depth - 1 ; "" ) ; // object name // current object is the front tab GetLayoutObjectAttribute( ~current ; "isFrontTabPanel" ) ; Max( $FrontTabPanels_depth ; 0 ) & " " & ~current & ¶ ) & FrontTabPanels ( Right ( ObjectNames ; Length( ObjectNames ) - Length( ~current ) - 1 ) ) ) // end Let ) // end If I just noticed that I should probably modify this function to clear the $FrontTabPanels_depth variable before it exists.
innodat Posted February 6, 2012 Author Posted February 6, 2012 This is interesting, thank you for sharing. What script do you use to restore them? If I understand correctly, the variable with the saved state(s) contains something like: 0 Tab_Drei 1 Tab_Mango I guess you could just trim on the left (2 characters).
dansmith65 Posted February 7, 2012 Posted February 7, 2012 This isn't a proper sample file or anything, but it does contain a script that should work. The script documentation is not accurate - I haven't gotten around to finishing it yet. TabControlSampleWORKINPROGRESS.zip
innodat Posted February 7, 2012 Author Posted February 7, 2012 Very nice! Thank you for sharing. I like this a lot.
dansmith65 Posted February 7, 2012 Posted February 7, 2012 Your welcome, I'm glad you like it. I thought it was pretty nifty too; I've never seen anyone actually read the bizarre output of LayoutObjectNames() function. Usually people just strip all the < and >, and end up with a flat list.
Recommended Posts
This topic is 5013 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