Trying a custom handler for several math fields

stephen barncard stephenREVOLUTION2 at
Fri Sep 13 01:53:44 EDT 2013

On Thu, Sep 12, 2013 at 9:51 PM, Vaughn Clement <vclement at> wrote:

> The current database I use is FileMaker Advanced and it is so well

yes but Filemaker can be limiting as it is so easy to use the pre-fab
scripting segments...with built in bumpers...

LC is the wide open spaces of "do anything".

Barncard's Baby Steps example

you just need to 'clean' the strings before doing math

pseudo code can help create visualize actual running code

put the data from the field into a variable
if character 1 of the variable is "$" then  delete character 1 of the
if commas are in the variable replace  comma with empty
use the cleaned variables to do the math
replace the $ and the comma

real code : put this into a button:

*on* mouseUp

   -- this is a comment -- two dashes, also could be used to 'turn off' a
line for tracing

   *local* tVar1,tVar2,tVar3

   *put* "$34,000" into tVar1  -- it could just as easily be --  *put* field
"A" into tVar1

   *put* "$120,000" into tVar2 -- it could just as easily be  --  put field
"B" into tVar2

   *if* char 1 of tVar1 is "$" *then* *delete* char 1 of tVar1

   *if* char 1 of tVar2 is "$" *then* *delete* char 1 of tVar2

   *replace* comma with empty in tVar1

   *replace* comma with empty in tVar2     *-- comma is actually a system

   *put* (tVar1 + tVar2) into tVar3   *-- (the math)*

   *put* "$" before tVar3 -- restore the dollar sign

   *put* comma before char -3 of tVar3  -- replace the comma

   *put* tVar3 *-- into message box*

*end* mouseUp

the message box will show   $154,000

obviously some exception code needs to be written to handle a variable
number of zeros, this is an ultra simple example to get you started.



the message box is your friend. It allows you to test out single line
expressions before you drop them into a script, or to test short scripts.

I don't think you are ready for the debugger yet...

Try working little bits at a time until you get the hang of the syntax.
Don't try to do too much at first. Do Little baby steps, then put the
pieces together.

Defining variables is not necessary but is good programming practice
anyway, and is a more comfortable style for programmers coming from other

You WILL struggle. and have to look a lot of things up and ask questions.
You will get frustrated. But after a while you will get it and I promise
you will be here helping others in a few months..... mark my words... this
is the friendliest, funniest and most helpful set of folks on this list you
will ever find for a programming language and you find us very helpful -
we've all been where you are right now at some point, even Hypercard pros
have trouble at first.

We will all help you to some extent, but ultimately you have to write the
code that does what you want. FUTZ around. experiment.

If you get hung up, work on another aspect.  Read the dictionary, and
examples, even if they don't apply to your particular application. You will
get ideas, try them out.

Don't expect to write an app in a day yet. Take your time. And the
documentation and examples are fine especially for what you are trying to
do now, it's just that the vocabulary is 10x the size and more versatile.

Stephen Barncard
San Francisco Ca. USA

more about sqb  <>

More information about the Use-livecode mailing list