Page 1 of 1

Field Calculation

Posted: Tue Dec 06, 2011 9:05 pm
by painnbt
i want to take the number in "Field 1" divide it by a number and place it in "Field 2". Then i want to have a drop down box and assign a value to each item in the drop down box, So that when that item is selected it will multiply the value of that item by the number in "Field 2" and display it in "Field 3" ... can i get some guidance

Re: Field Calculation

Posted: Wed Dec 07, 2011 1:10 am
by dunbarx
All these tasks are simple and will be a great learning experience.

Make three fields, a button and a pulldown menu. Put your number into field 1. In the button script say something like:

on mouseUp
put fld 1 / yourNumber into fld 2 --yourNumber is, well, your number
end mouseUp

In the script of the pulldown, you need to understand that the appropriate handler is "menuPick", because that is what you are doing, picking a menuItem.

on menuPick pItemName
put pItemname * fld 2 into fld 3
end menuPick

Of course you must load the pulldown with numbers.

Read up on all these terms, play around, and write back.

Craig Newman

Re: Field Calculation

Posted: Wed Dec 07, 2011 2:43 pm
by painnbt
thank you for the response .. Is there a way to bind a value to a choice in my pulldown menu lets say i have choice A, B, and C and i want the value of 20 for A 40 for B and 60 for C. That way when i do my calculation for field 3 i could choose A and it would multiply field 2 by 20 and display in field 3

Re: Field Calculation

Posted: Wed Dec 07, 2011 3:38 pm
by bn
Hi painnbt,

in the properties inspector assing to the pulldown button your A B C

then set the script of the pulldown button to

Code: Select all

on menuPick pItemName
   switch pItemName
      case "A"
         put field 2 / 20 into field 3
         break
      case "B"
         put field 2 / 40 into field 3
         break
      case "C"
        put field 2 / 60 into field 3
         break
   end switch
end menuPick
you might want to look up the switch control structure in the dictionary.

Kind regards

Bernd

Re: Field Calculation

Posted: Wed Dec 07, 2011 3:56 pm
by painnbt
Thank you for your reply but i have gone a little bit of a different route. I was thinking about who would be using this little tool and chose to use buttons instead and did my calculations per button. Here is my next question basing this on the prior sugestion i am using fld 1 fld 2 and so on here is my question how do i know what box is designated as fld 1 and fld 2? is there a way i can assign this ?

Re: Field Calculation

Posted: Wed Dec 07, 2011 4:25 pm
by bn
Hi painnbt,

it is probably better to give the fields a name: in the properties inspector you assign a unique name to the field. From then on you refer to the field by name:

Code: Select all

put field "fieldWithName" into field "FieldWithAnotherName"
That way you avoid field 1, field 2 etc. because if you change the layer of the fields (in the inspector "Size and Position" by bringing a field to the front or to the back, their numbering will be different.

And please always put the name of a field and any other control into quotes. Everything in livecode which is a literal should be quoted.

I might suggest that you work through the tutorials

http://runrev.com/developers/lessons-an ... tutorials/

also have a look at the lessons.

Yet another good resource might be the scripting conferences

http://www.runrev.com/developers/lesson ... nferences/

Kind regards

Bernd

Re: Field Calculation

Posted: Wed Dec 07, 2011 5:13 pm
by painnbt
Thanks guys for your help this has been a learning project for calculating scrap i plan on doing more with it and i will be posting more questions here :D