On Fri, 11 Aug 2000, David Bovill wrote:

> A number of built in commands both set the variable it, and return something to the 
>result function (such as "Cancel"). Is there a way of defining your own handler to do 
>the same thing?
> 
> An example might help:
> 
> on extractQuoted someText
>   local textFound
>   put "^.*" & kwote("(.*)") & ".*" into quoteReg
>   if matchText(someText, quoteReg, textFound) is false then
>     set it to textFound
>     return empty
>   else
>     set it to empty
>     return "Not found"
>   end if
> end extractQuoted
> 
> This way I can use the same handler to destinguish between finding something that is 
>empty and "not finding it" - by checking the result.

Sorry, "it" is a local variable and so you can't return a value in
it. There are several of other ways to return values, though.  From
worst to best:
1) use a global variable
2) use a custom property on some object (e.g., the one with the handler)
3) use call-by-reference parameters.  Using your example:

on extractQuoted someText, @returnedtext
  put "^.*" & kwote("(.*)") & ".*" into quoteReg
  if matchText(someText, quoteReg, returnedtext)
  then return empty
  else return "Not found"
end extractQuoted

You'd call it like:
  local myfoundtext
  extractQuoted "some string", myfoundtext
  if the result is empty
  then put myfoundtext into field 1

Even better probably would be to make your handler a function, which
makes the calling script even shorter:
  local myfoundtext
  if extractQuoted("some string", myfoundtext)
  then put myfoundtext into field 1

The only tricky part when using call-by-reference parameters is that
you have to be sure to declare them before you pass them to another
handler.
  Regards,
    Scott

********************************************************
Scott Raney  [EMAIL PROTECTED]  http://www.metacard.com
MetaCard: You know, there's an easier way to do that...


Archives: http://www.mail-archive.com/metacard%40lists.best.com/
Info: http://www.xworlds.com/metacard/mailinglist.htm
Please send bug reports to <[EMAIL PROTECTED]>, not this list.

Reply via email to