Calculating a number?

Thomas McGrath III 3mcgrath at adelphia.net
Thu Mar 24 09:37:46 EST 2005


John,

The easiest thing to do is create a field called "myTotal" and two 
other fields "myOne" and "myTwo" and a button "Calculate" -- select the 
field tool and drag a field to your new main stack. Then open the 
inspector and change the names to each  i.e. "myOne" etc. select the 
button and open its script and enter this:

on mouseUp
	put field "myOne" + field "myTwo" into field "myTotal"
end mouseUp

enter numbers into the two fields and hit the button

Then change the + to * and hit the button again.
Then change the * to / and hit the button.
Then change the / to - and hit the button.
Then change the script to:
add 1 to field "myTwo"
or:
subtract 3 from field "myTotal"


In case you got lost here I put a simple sample stack in my user space 
for you to use:
username: mcgrath3
stack: simple math

samples from the docs using existing fields and a mix of variables and 
fields and pop up choices: -- change the fields to names of fields you 
make etc.

add field "New" to summaryOfInventory -- variable
add qty * price to last line of myOrder -- variables

put 2 + 2 into fourContainer
set the layer of field myNumber to (myNumber + 2)

put -24 into myContainer
put theRight - theLeft into theWidth
put myArray - 17 into adjustedValues

subtract 15 from oldNumber
subtract field "Input" from word 2 of field "Output"
subtract monthlyExpenses from monthlyTotals

divide it by 50
divide field "Total Income" by 12
divide line x of field "Expenses" by percentageRate
divide yearlyTotals by 52

multiply field 17 by it
multiply yearlyTotals by yearlyPercentages
multiply line thisLine of myVariable by theFactor

get 3 * 5 -- evaluates to 15
put thisNumber * it into field "Result"
put (3 + commonFactor) * 4 into tempVariable


>  enter 5 numbers and select three numbers from three different drop 
> down menus. add 7 to field "Previous Amount" -- existing field

ADVANCED SCRIPT -- not tested

Set up a field called "myUserNumbers" and three drop down menus with 
your pre listed numbers in them called "myDropOne", "myDropTwo", 
"myDropThree" and of course your field "myPreviousAmount" (titled 
"Previous Amount") Lastly a button "myCalculate" and a field "mytotal" 
to put the total into.


In drop menu one put this: -- do the same for each drop menu changing 
the filed or global to two and then three for each one you have.
on menuPick theItem -- in a pulldown menu
	theItem into field "myDropOne" -- or do this
	-- put theItem into GmyDropOne -- use a global - you must then declare 
your globals
end menuPick

on mouseUp
	if field "myUserNumbers" is not empty then -- make sure we put 
something into the user field
		put field "myUserNumbers" into lone
		put field "myDropOne" into mydropone -- if the choice was put into a 
field
		put field "myDropTwo" into mydroptwo -- same here
		put field "myDropThree" into mydropthree -- same here
		-- or --
		-- put GmyDropOne + GmyDropTwo + GmyDropThree into mytotal -- if you 
use globals then use this
		put lone + mydropone + mydroptwo + mydropthree into mytotal -- adds 
field and three popup menu items
		put mytotal into field "mytotal"
		----
		put field "myPreviousAmount" + 7 into field "myPreviousAmount" -- as 
per your email ???
		---
		put mytotal + 7 into field "myPreviousAmount" --- etc.
	else
		answer "Please enter a number." with "OK"
	end if
end mouseUp


On Mar 24, 2005, at 1:33 AM, John Smiley wrote:

> I previously posted how I am a newbie and got tremendous response from 
> the list. After having explored a bit and tinkered with the program, I 
> have a question about how to do something.
>
> I am wanting to create an application where the user enters data into 
> several fields and the software calculates the answer. In the final 
> product the user will enter 5 numbers and select three numbers from 
> three different drop down menus. The software will calculate a number 
> based on this input and compare the result to 8 other variables the 
> user selects and come up with a "yes" or "no" result.
>
> Rather than trying to find out how to do all of that in one question, 
> I think it best if I learn first how to write the code to calculate 
> (either add or multiply) a number between two fields and have the 
> result output into a third field first.
>
> Anyone care to explain?
>
> Thanks -
>
> John Smiley
> New Orleans, LA
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
>

Thomas J. McGrath III
SCS
1000 Killarney Dr.
Pittsburgh, PA 15234
412-885-8541


More information about the use-livecode mailing list