Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Dynamic Global Variables [" "] vs. [ ¶]

Featured Replies

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?

Hi, I improved your function:


Evaluate("

Let(

$$" & name & "[" & repetition & "] = ""  & Substitute( value; "¶"; "¶") &  "";

""

)

")

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

)

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.

It works for me. How are you testing the result?

  • 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

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/

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

""

)

")

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

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

] ;

""

)

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

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

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.

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

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

  • Author

Very nice! Thank you for sharing. I like this a lot.

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

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.