Parameter Passing in FM8?

5 messages Options
Embed this post
Permalink
Michael Diehr

Parameter Passing in FM8?

Reply Threaded More More options
Print post
Permalink
Has anyone come up with a good way to pass parameters to scripts in FM8?

I have been using the trick where you do this inside the script
   Let( Evaluate(GetScriptParameter), X )
for each variable, and you call the script with the following syntax:
   X="foo" ; Y="bar"; Z="foobar"

However, there are some things I don't like about this way of doing it.

1. Documentation -- what's the best way to show that a Script has  
parameters? I find myself having to open the script to double-check I  
have the parameters named properly.

2. Syntax / Ease of use -- creating the calling parameter string is  
ugly, lots of escaped-quotes inside quotes, i.e. to make this string:
   X="foo" ; Y="bar"; Z="foobar"
you need to write
   X=\"" & TableA::FieldA & "\" ; Y=\"" & TableA::FieldB & "; Z=\"" &  
TableA::FieldC & "\""

Ugly!

3. Missing parameters -- this is an evil one! I just discovered that
   "Let (Evaluate(GetScriptParameter), X)"
returns "?" if the parameter wasn't included. I'd much rather it  
returned the empty string ""

4. Error checking -- how does one easily trap for missing parameters?

So in short, the power is enticing, but I'm finding the use a bit  
ugly and error-prone.

Some ideas:

A. Naming scripts? Maybe I should start including the parameter names  
in my script names, e.g. "OpenNewWindow[window,layout,height,width]"  
This might make it much easier to script as you can get the parameter  
names w/o having to open the script?

B. Each script that has parameters passed should immediately assign  
them to local variables of the same name, e.g.
   Set Variable $X = Let(Evaluate(GetScriptParameter), X)
   Set Variable $Y = Let(Evaluate(GetScriptParameter), Y)
This will probably help with readability and debugging.

C. Creating the parameter string is still a pain. It would be really  
nice to be able to call a script with a normal parameter list, like  
this:

   Window="MyNewWindow", X=500, Y=Table::FieldA

I wonder if I could create a custom function which would put it  
together doing all the quoting & escaping for me, so I ended up with  
this:

   "Window=\"MyNewWindow\", X=500, Y=\"" & Table::FieldA & \""


Ideas?


--

Convert your FileMaker CDML to Lasso Professional 8 FREE:
http://www.omnipilot.com/article.lasso?id=8630

Lasso is the secure corporate alternative to open-source and  
Microsoft for publishing databases online.

------------------------------
This list is a free service of OmniPilot Software, Inc.
http://www.omnipilot.com/
Search the list archives:
http://www.listsearch.com/filemakerprotalk.lasso
Manage your subscription:
http://www.listsearch.com/filemakerprotalk.lasso?manage
David Franklin

Re: Parameter Passing in FM8?

Reply Threaded More More options
Print post
Permalink
I do it using a custom function and positioned parameters rather than named parameters.  Here's my function:

GetParam(number)

Case(

(Number > PatternCount(Get ( ScriptParameter );"|")) and (Number < PatternCount(Get ( ScriptParameter ) ;"|") + 2);
Right (
Get ( ScriptParameter );
Length (Get ( ScriptParameter )) - Position (Get ( ScriptParameter ); "|"; 1; Number - 1));

Number ≤ PatternCount(Get ( ScriptParameter );"|");
Middle (
Get ( ScriptParameter );
(Position (Get ( ScriptParameter ); "|"; 1; Number - 1) + 1);
Position (Get ( ScriptParameter ); "|"; 1; Number) - Position (Get ( ScriptParameter ); "|"; 1;Number - 1) - 1);

"")

Then I use a naming convention for my scripts:

CalculateVolume(Length,Width,Height)

So in my script when I want to get the length I simply call GetParam(1).  It's easy to remember which parameter is what because it's listed at the top of the script in the name.

Passing parameters still requires a little bit of coding but it's fairly simple because it's simply a vertical pipe "|" delimited list:

CalculateVolume(Dimensions::nLength & "|" & Dimensions::nWidth & "|" & Dimensions::nHeight)

The custom function handles missing parameters at the end by returning "" for them.  Also, to skip a parameter you can simply do:

ScriptName(Param1 & "||" & Param3)

I think this is the simplest way to handle it.

-Dave

David Franklin
President/Technical Director
Computer Bakery, LLC
(212) 712-1600
[hidden email]

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Michael Diehr
Sent: Sunday, December 04, 2005 12:23 AM
To: [hidden email]
Subject: Parameter Passing in FM8?

Has anyone come up with a good way to pass parameters to scripts in FM8?

I have been using the trick where you do this inside the script
   Let( Evaluate(GetScriptParameter), X )
for each variable, and you call the script with the following syntax:
   X="foo" ; Y="bar"; Z="foobar"

However, there are some things I don't like about this way of doing it.

1. Documentation -- what's the best way to show that a Script has  
parameters? I find myself having to open the script to double-check I  
have the parameters named properly.

2. Syntax / Ease of use -- creating the calling parameter string is  
ugly, lots of escaped-quotes inside quotes, i.e. to make this string:
   X="foo" ; Y="bar"; Z="foobar"
you need to write
   X=\"" & TableA::FieldA & "\" ; Y=\"" & TableA::FieldB & "; Z=\"" &  
TableA::FieldC & "\""

Ugly!

3. Missing parameters -- this is an evil one! I just discovered that
   "Let (Evaluate(GetScriptParameter), X)"
returns "?" if the parameter wasn't included. I'd much rather it  
returned the empty string ""

4. Error checking -- how does one easily trap for missing parameters?

So in short, the power is enticing, but I'm finding the use a bit  
ugly and error-prone.

Some ideas:

A. Naming scripts? Maybe I should start including the parameter names  
in my script names, e.g. "OpenNewWindow[window,layout,height,width]"  
This might make it much easier to script as you can get the parameter  
names w/o having to open the script?

B. Each script that has parameters passed should immediately assign  
them to local variables of the same name, e.g.
   Set Variable $X = Let(Evaluate(GetScriptParameter), X)
   Set Variable $Y = Let(Evaluate(GetScriptParameter), Y)
This will probably help with readability and debugging.

C. Creating the parameter string is still a pain. It would be really  
nice to be able to call a script with a normal parameter list, like  
this:

   Window="MyNewWindow", X=500, Y=Table::FieldA

I wonder if I could create a custom function which would put it  
together doing all the quoting & escaping for me, so I ended up with  
this:

   "Window=\"MyNewWindow\", X=500, Y=\"" & Table::FieldA & \""


Ideas?


--

Convert your FileMaker CDML to Lasso Professional 8 FREE:
http://www.omnipilot.com/article.lasso?id=8630

Lasso is the secure corporate alternative to open-source and  
Microsoft for publishing databases online.

------------------------------
This list is a free service of OmniPilot Software, Inc.
http://www.omnipilot.com/
Search the list archives:
http://www.listsearch.com/filemakerprotalk.lasso
Manage your subscription:
http://www.listsearch.com/filemakerprotalk.lasso?manage




--

Convert your FileMaker CDML to Lasso Professional 8 FREE:
http://www.omnipilot.com/article.lasso?id=8630

Lasso is the secure corporate alternative to open-source and  
Microsoft for publishing databases online.

------------------------------
This list is a free service of OmniPilot Software, Inc.
http://www.omnipilot.com/
Search the list archives:
http://www.listsearch.com/filemakerprotalk.lasso
Manage your subscription:
http://www.listsearch.com/filemakerprotalk.lasso?manage
G. Pupita

Re: Parameter Passing in FM8?

Reply Threaded More More options
Print post
Permalink
In reply to this post by Michael Diehr
Hi Michael

> Has anyone come up with a good way to pass parameters to scripts in  
> FM8?
>
> I have been using the trick where you do this inside the script
>   Let( Evaluate(GetScriptParameter), X )
> for each variable, and you call the script with the following syntax:
>   X="foo" ; Y="bar"; Z="foobar"
>
> However, there are some things I don't like about this way of doing  
> it.
>
> 1. Documentation -- what's the best way to show that a Script has  
> parameters? I find myself having to open the script to double-check  
> I have the parameters named properly.
>
> 2. Syntax / Ease of use -- creating the calling parameter string is  
> ugly, lots of escaped-quotes inside quotes, i.e. to make this string:
>   X="foo" ; Y="bar"; Z="foobar"
> you need to write
>   X=\"" & TableA::FieldA & "\" ; Y=\"" & TableA::FieldB & "; Z=\""  
> & TableA::FieldC & "\""
>
> Ugly!
>
> 3. Missing parameters -- this is an evil one! I just discovered that
>   "Let (Evaluate(GetScriptParameter), X)"
> returns "?" if the parameter wasn't included. I'd much rather it  
> returned the empty string ""
>
> 4. Error checking -- how does one easily trap for missing parameters?
>
> So in short, the power is enticing, but I'm finding the use a bit  
> ugly and error-prone.
>
> Some ideas:
>
> A. Naming scripts? Maybe I should start including the parameter  
> names in my script names, e.g. "OpenNewWindow
> [window,layout,height,width]" This might make it much easier to  
> script as you can get the parameter names w/o having to open the  
> script?
>
> B. Each script that has parameters passed should immediately assign  
> them to local variables of the same name, e.g.
>   Set Variable $X = Let(Evaluate(GetScriptParameter), X)
>   Set Variable $Y = Let(Evaluate(GetScriptParameter), Y)
> This will probably help with readability and debugging.
>
> C. Creating the parameter string is still a pain. It would be  
> really nice to be able to call a script with a normal parameter  
> list, like this:
>
>   Window="MyNewWindow", X=500, Y=Table::FieldA
>
> I wonder if I could create a custom function which would put it  
> together doing all the quoting & escaping for me, so I ended up  
> with this:
>
>   "Window=\"MyNewWindow\", X=500, Y=\"" & Table::FieldA & \""
I use a custom function by Shaun Flisakowsi
You can find it at his site
http://www.spf-15.com/fmExamples/

It's named Property list

Pretty slick, simple and functional, overcomes many script  
parameter's problems

Ciao
G. Pupita
Certified FileMaker 7 Developer
FSA Associate


--

Convert your FileMaker CDML to Lasso Professional 8 FREE:
http://www.omnipilot.com/article.lasso?id=8630

Lasso is the secure corporate alternative to open-source and  
Microsoft for publishing databases online.

------------------------------
This list is a free service of OmniPilot Software, Inc.
http://www.omnipilot.com/
Search the list archives:
http://www.listsearch.com/filemakerprotalk.lasso
Manage your subscription:
http://www.listsearch.com/filemakerprotalk.lasso?manage
Tom Fitch

Re: Parameter Passing in FM8?

Reply Threaded More More options
Print post
Permalink
In reply to this post by Michael Diehr
Put the "ugly" code into a custom function. You can use numbered  
parameters, but I prefer named parameters, so I don't have to put  
them in any particular order. It's easy enough to add a check for  
IsEmpty( Get ( ScriptParameter ) ) too. Once you've got it set up,  
it's as easy as Grab( whatever ).

I suppose you could put parameter names in script names, but I've  
found it sufficient to put the params in a script comment at the top  
of the script.

Tom Fitch
FileMaker 7 Certified Developer
Portland, Oregon


On Dec 3, 2005, at 9:22 PM, Michael Diehr wrote:
> Has anyone come up with a good way to pass parameters to scripts in  
> FM8?


--

Convert your FileMaker CDML to Lasso Professional 8 FREE:
http://www.omnipilot.com/article.lasso?id=8630

Lasso is the secure corporate alternative to open-source and  
Microsoft for publishing databases online.

------------------------------
This list is a free service of OmniPilot Software, Inc.
http://www.omnipilot.com/
Search the list archives:
http://www.listsearch.com/filemakerprotalk.lasso
Manage your subscription:
http://www.listsearch.com/filemakerprotalk.lasso?manage
steve harley

Re: Parameter Passing in FM8?

Reply Threaded More More options
Print post
Permalink
In reply to this post by Michael Diehr
Quoting Tom Fitch <[hidden email]>:
> Put the "ugly" code into a custom function. You can use numbered  
> parameters, but I prefer named parameters, so I don't have to put  
> them in any particular order.

named parameters also make code clearer, and they facilitate
making parameters optional

FM8 makes named parameters even easier to use; i haven't
seen this technique described anywhere yet:

in your calls, use local variable names ("$" prefix) within
all your parameter strings

define a custom function with no arguments:

  get_params ()
    Evaluate ("let ([" & Get(ScriptParameter) & "]; 1)")

this converts all the parameters to local variables and
returns 1 as an indicator of success (useful if you Set
Error Capture [On], and there is an error during parameter
evaluation)

in the called script, simply invoke the custom function via
a "stub" if:

  Set Variable [$got_params; get_params()]

now all your parameters are available as local variables;
if you want a parameter to have a default value when it isn't
supplied, just set it as a local variable prior to the call
to get_params()



----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.


--

Convert your FileMaker CDML to Lasso Professional 8 FREE:
http://www.omnipilot.com/article.lasso?id=8630

Lasso is the secure corporate alternative to open-source and  
Microsoft for publishing databases online.

------------------------------
This list is a free service of OmniPilot Software, Inc.
http://www.omnipilot.com/
Search the list archives:
http://www.listsearch.com/filemakerprotalk.lasso
Manage your subscription:
http://www.listsearch.com/filemakerprotalk.lasso?manage