_setVariable ( )

Function stats

Average user rating
5.0000
34
160
9999
Support
FileMaker 7.0 +
Date posted
22 December 2008
Last updated
23 December 2008
Version
Recursive function
No

Author Info
 The Shadow

22 functions

Average Rating 4.3

author_avatar



 

Function overview

Prototype

_setVariable  ( varName;   index;   value )


Parameters

varName  The global variable name


index  The index to set


value  The value to set


Description

Tags:  Variables  

This function is the corresponding one to _getVariable(), which allows the usage of dynamic global variables - one's you don't know the name of when you wrote the code.

These variables can be leveraged to create "objects" that are stored within various global variables, for example, see:
http://fmforums.com/forum/showtopic.php?tid/187684

Examples

Sample input

_setVariable( "$$a"; 1; "Foop" )


Sample output

$$a[1] is set to "Foop"

 

Function code

// This extra let ensures we don't lose the type of value as we would by using Quote()
Let( $_varSetArg = value;
Evaluate( "Let( " & varName & "[" & index & "]=$_varSetArg; $_varSetArg )" )
)

// ===================================
/*

    This function is published on FileMaker Custom Functions
    to check for updates and provide feedback and bug reports
    please visit http://www.fmfunctions.com/fid/160

    Prototype: _setVariable( varName; index; value )
    Function Author: The Shadow (http://www.fmfunctions.com/mid/34)
    Last updated: 23 December 2008
    Version: 1.1

*/
// ===================================

 

Comments

Genx
22 December 2008



Type Preservation = Sweet!!
  General comment
Fabrice
23 December 2008



Yes, you're making a big point here, thank you!
I modified VariablesLog accordingly, and I posted a new function on which I would really like to have your feed-back. http://www.fmfunctions.com/fname/datatype
It's now in beta version, but if it was juged as correct, you could implement it in _getVariable, and I would in VariablesLoadFromLog and xml2var
  General comment
Fitch
23 December 2008



This is one of those functions where I can see what it does, and I understand how it does it, and it's interesting, but... it would be helpful to provide an explanation of where/why this would be useful, perhaps a link if it's been discussed elsewhere.
  General comment
The Shadow
23 December 2008



Fitch, I use this technique for my "FM Objects" stuff that I was pushing for a while, see:

Matrix Objects (and a Queue):
http://fmforums.com/forum/showtopic.php?tid/187684

Date Formatter:
http://fmforums.com/forum/showtopic.php?tid/187938/

  General comment
The Shadow
23 December 2008



Fabrice, while your DataType() CF looks useful, _getVariable doesn't need it, as _setVariable preserves the type in the FileMaker global variable space, so _getVariable can just access the value directly, and it will still be a container/date/number, etc. - whatever you passed in to set it.
  General comment