February 4, 201214 yr 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?
February 4, 201214 yr Hi, I improved your function: Evaluate(" Let( $$" & name & "[" & repetition & "] = "" & Substitute( value; "¶"; "¶") & ""; "" ) ")
February 4, 201214 yr 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 ) & " ; "" )" )
February 4, 201214 yr 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.
February 4, 201214 yr 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.
February 4, 201214 yr Author 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
February 4, 201214 yr 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/
February 5, 201214 yr 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) & ""; "" ) ")
February 5, 201214 yr 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).
February 5, 201214 yr 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 = "" ] ; "" )
February 5, 201214 yr Good point. I usually use namespacing to prevent collision, but I like your method of clearing the variable when finished with it.
February 6, 201214 yr Author 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/ :)
February 6, 201214 yr 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.
February 6, 201214 yr Author 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).
February 7, 201214 yr 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
February 7, 201214 yr 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.
Create an account or sign in to comment