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 4730 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

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?

Posted

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 ) & " ; "" )"

)

Posted

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.

Posted

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

Posted

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/

Posted

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) & "";

""

)

")

Posted

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

Posted

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

] ;

""

)

Posted

Good point. I usually use namespacing to prevent collision, but I like your method of clearing the variable when finished with it.

Posted

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/ :)

Posted

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.

Posted

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

Posted

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.

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