You will have to set a field per variable
As Lynday suggested set field will do the work. You will need to set up a script and possibly a table tied back to the user.
The issue is do you want this users settings or the last user.
If it is the last user a single record and set of fields will do. If it is a specific user you will have to tie back to the user id
So you will need to add an on close script that goes through all of your global variables and saves them. Then have the on open script read the values and set the variables.
For a new user you may want to have default values.
Hope this helps
1 of 1 people found this helpful
...I don't see a way of getting a current list of defined global variables. Is it possible?
To answer your question as asked, there isn't one - unless you institute your own process to keep track of the names of variables, either as they're declared or in a default register of variables that you maintain during development.
That said, I think the idea of pushing the contents of variables into an NV-pair string and storing it in the relevant record in the user table is sound. You should be able to create custom functions that will accept a list of variable names and return the corresponding NV pairs, and a counterpart that will recieve the NV-pair string and re-instantiate all the named variables (the ones that have values...) in a single call. So providing you're able to institute your own methodology for tracking the names of all global variables that may be in use, the rest should be relatively straightforward.
R J Cologon, Ph.D.
FileMaker Certified Developer
Author, FileMaker Pro 10 Bible
NightWing Enterprises, Melbourne, Australia
I want to be able to save the current list of global variables and their values when a user quits FileMaker, so I can restore them the next time the user logs back in. Is there a way to get a list of currently defined global variables in FileMaker? I was thinking of saving the name value pairs in the user table on log out and then restore them on login. But I don't see a way of getting a current list of defined global variables. Is it possible?
Hi, Some of the other people is asking whether you want it for the last or all users. But your question is very clear indeed. The anser is:
- Have a user table with one record for each user. This can come in handy for many other purposes, including handling of accounts (creating, enabling, disabling, setting passwords etc).
- Create a field for each (global) variable you want to store*.
- Make an very simple script that runs when the database is closed: Setting each global variable into their relevant fields.
- When starting up the next time, the first script running (the startup/ini script) should just set the global variables to the values from the users record.
Is it a one file solution. If not you must have a reference to the user table in the file where you are using the global variables and the script must run in this file. This is because a $ variable is only remembered within the script, the $$ variable is only remembered within the session and the file.
I did suggest that you should create a field for each variable in the user table. Depending on the size of your solution and the number of global variables you want to store this may work fine. But you are going to store a lot of global variables and assuming that many more are being added: Consider having a table related to the user table where you create a new related record for each variable with the name of the variable and the value.
Thanks Ray, this is the answer I was looking for. The number of global variables that need to be restored depend on what the user is doing during the session, so I can't create a set number of fields to store the values. I already had the idea for storing the NV-pairs as a string, so I just need to create a way to generate that value list string and then restore them when the user logs in next time. I was just hoping FileMaker could generate that list for me.
Thanks for the input.
I had a similar issue some time ago where I wanted to save variables, which can be reused at will. The following are a custom functions which are used for achieving this goal:
SetCache ( cacheList ; name ; value ):
Let ( [
CacheList = RemoveExtraReturns ( cacheList ) ;
ArraySize = ValueCount ( CacheList ) ;
IndexLinePosition = Position ( CacheList ; name ; 1 ; 1 ) ;
IndexPosition = ValueCount ( Left ( CacheList ; IndexLinePosition - 1 ) ) + 1 ;
SemiColon = If ( IndexPosition = ArraySize or IndexLinePosition = 0 ; Null ; " ; " ) ;
IndexLineValue = GetValue ( CacheList ; IndexPosition ) ;
ReplaceIndexLineValue = name & " = " & value & SemiColon ;
NewIndexLineValue = CacheList & If ( IsEmpty ( CacheList ) ; Null ; " ; " ) & EOL & name & " = " & value & SemiColon ] ;
If ( IndexLinePosition ≥ 1 ; Substitute ( CacheList ; IndexLineValue ; ReplaceIndexLineValue ) ; NewIndexLineValue )
GetCache ( name ):
RetrieveValue ( Substitute ( Evaluate ( "Main::Cache_gt" ) ; EOL ; " " ) ; name )
RetrieveValue ( values ; name ):
Let ( [
String = Substitute ( text ; [ "\"" ; "^^" ] ; [ " ;" ; ";" ] ; [ ";" ; "\" ;" ] ; [ "= " ; "=" ] ; ["=" ; " = \"" ] ; ["¶" ; "~~" ] ; [ " and " ; " xandx " ] ; [ " or " ; " xorx " ] ) & "\"" ;
Eval = Evaluate ( "Let ( [" & String & "] ;" & name & " )" ) ;
Result = Substitute ( Eval ; [ "^^" ; "\"" ] ; [ "~~" ; "¶" ] ; [ "xandx" ; "and" ] ; [ "xorx" ; "or" ] )
If ( Result ="?" ; Null ; Result )
A single global field is needed and since FileMaker text fields store 2GB of data, you can store an unlimited number of variables.
Whlle this will probably work, one question though: Is it not a very complicated way to solve this problem: Storing a known set of global variables in a user record?