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=8630Lasso 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.lassoManage 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=8630Lasso 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.lassoManage your subscription:
http://www.listsearch.com/filemakerprotalk.lasso?manage