ISO FileMaker Magazine: FileMaker Video Tutorials, Templates, Help & More

Navigation

Video Browser

Scriptology Video Browser

Tools & Resources

Variables

Simulating a Basic Key / Value Array

Posted by: aflgenx / Thursday, September 27, 2007 – 10:04pm

Alright guys, been busy so pardon the greater than one month gap. This is more on the whole numeric addressing issue we have with repeating vars and fields... its really annoying and puts limits on what can be achieved.

So, we want to simulate text based key's that are available in every programming language known to man - one method I don't mind (though i haven't extensively run speed tests on it):

Custom Function: getValueFromArray( array ; key)
Let( [
newList = Substitute( array ; "\," ; "|||" ) ;
newList = ¶ & Substitute( newList ; "," ; "¶" ) & ¶;
newList = Substitute( newList ; "|||" ; "," );
keyStart = Position( newList ; ¶ & key & "=>" ; 1 ; 1 ) ;
valueStart = keyStart + Length(key)+3;
valueEnd = Position( newList ; "¶" ; valueStart ; 1 )];
If( PatternCount( newList ; ¶ & key & "=>" ) ; Middle( newList ; valueStart ; valueEnd - valueStart) ; "?" )
)

Method for setting the key / value array:
$array = "key=>value,sentance=>I am a value\, values are cool!!,key3=>\"value3\""

Now, so lets say we wanted to extract the value for sentance from that array:
getValueFromArray( $array ; "sentance" ) which would return: I am a value, values are cool!!
getValueFromArray( $array ; "key3" ) would return "value3".

I hope this has been a fun and eductational experience ;)

Cheers guys, will try build a bit on this and run some speed tests over the next few weeks, in the mean time, behave yourselves!!

Filed under: |

Dynamic Variables

Posted by: aflgenx / Tuesday, June 26, 2007 – 8:10am

Hi Guys,

I recently had the need (or more likely the desire) to set global variables dynamically..

As most of you will know, Set variable allows you to specify a dynamic value and repetition, but not a dynamic name for your variable. This often leads you to store info in a delimited list within one repetition when you need to store multiple peices of information per one subject.

This will soon make your scripts become messy and the logic harder to follow

Hence two small custom functions:

Custom Function: SetGlobalVariable( name ; value ; repetition)
Evaluate("Let( $$" & name & "[" & repetition & "] = \"" & value & "\" ; \"\" )" )

Example Usage: SetGlobalVariable( "record_" & table::primaryKey ; table::aField ; 1 )

If your primaryKey field contained "991" and your aField field contained "Alex!!" -
This would be the equivalent of using the script step: Set Variable( $$record_991[1] ; Value: "Alex!!" ) ..
or otherwise writing: Let( $$record_991[1] = "Alex!!" ; "" )

Which means that if you were to now retrieve the value of $$record_991 - you would get "Alex!!" as the value returned.

Call: GetGlobalVariable( name ; repetition)

Custom Function: GetGlobalVariable( name ; repetition)
Evaluate("$$" & name & "[" & repetition & "]" )

Example Usage: GetGlobalVariable( "record_" & table::primaryKey ; 1 )
Which would (where primaryKey = 991 and the variable was set as above) return "Alex!!"

These examples aren't great, but they certainly simplify my scripts and I hope they'll help someone else out.

Syndicate content

Be Notified!

Let us tell you when a new video is posted. We'll send you an email with a direct link right to your email inbox.
Make sure and whitelist (or add to your address book editor@filemakermagazine.com

Give your FileMaker interface a beautiful overhaul, make your layouts look great!Theme Box 150 Take control of your users' permissions using the Scriptology Permissions Template!Perms Box 150

iPod Video

Magazine IPod Small
Click to watch the video

FileMaker Reference Tool