4 Replies Latest reply on Mar 9, 2012 11:29 AM by Babeteflonblue

# How to get the value from textInput Component to perform calculation?

I need some help here...I'm trying to get the value of user input from the TextInput Component which is the age, height and weight to calculate the bmr and display the result in member("result").text.

How am i suppose to let the integer pass through in order for me to perform calculation? Would appreciate if anyone can help me out with this, thanks!

Below are the formula :

The Harris Benedict equation estimates BMR:

For women: (9.56 x w) + (1.85 x h) – (4.68 x a) + 655

For men: (13.75 x w) + (5 x h) – (6.76 x a) + 66

• ###### 1. Re: How to get the value from textInput Component to perform calculation?

Put this in your "Done" button's behavior: (assuming you have a global variable for male vs female, called globalGender--change to what ever you have)

global globalGender

if globalGender = "Female" then

member("result").text = (9.56 x value(member("weight").text)) + (1.85 x value(member("height").text)) – (4.68 x value(member("age").text)) + 655

else

member("result").text = (13.75 x value(member("weight").text)) + (5 x value(member("height").text)) – (6.76 x value(member("age").text)) + 66

end if

• ###### 2. Re: How to get the value from textInput Component to perform calculation?

Assumed that this section is only for male ...it still show error saying script error : String expected for

on mouseDown

member("result").text = (13.75 * value(member("weightText").text)) + (5 * value(member("heightText").text)) - (6.76 * value(member("ageText").text)) + 66

end

Do i have to add in "put sprite(x).text -- where x is the number of the sprite that is the text input." ?

• ###### 3. Re: How to get the value from textInput Component to perform calculation?

My mistake. You can only asign a string to the text property of a text member. Just need to convert the value returned to a string using the string function.  Use this

member("result").text =  string((13.75 * value(member("weightText").text)) + (5 * value(member("heightText").text)) - (6.76 * value(member("ageText").text)) + 66)

• ###### 4. Re: How to get the value from textInput Component to perform calculation?

Thank you so much! I knw where is my previous mistake as well :-)

By the way i change the member("weightText").text into sprite("weightText").text instead... I totally have no idea about the String thing.. Anyway thanks for your help and now i finally completed my project! Cheers~