How to use the blocks to create a calculation

Hi all this is my first post i hope someone can help.
Using the App Inventer how can i have a part of the app able to do the following calculation:

(# x 50) / #

the # are numbers the user can imput and when a button ''Calculate'' is hit it calculates the result and puts it on the screen.

how would i use the blocks to do that? is it even posible?

thanks any help would be much appreciated

Input values using a TextBox TextBox
Create the equation using the Math Blocks Math blocks

In a Button.Click event handler include the following

TextBox1.Text * 50 / TextBox2.Text = Label1.Text

Something like the examples shown in the tutorials
Chapter 16. Programming Your App's Memory
Chapter 18. Programming Your App to Make Decisions
Chapter 21. Defining Procedures

Here are some resources to help you learn to use the AI2 tools. A very good way to learn App Inventor is to read the free Inventor's Manual here in the AI2 free online eBook http://www.appinventor.org/book2 ... the links are at the bottom of the Web page. The book 'teaches' users how to program with AI2 blocks.

There is a free programming course here http://www.appinventor.org/content/CourseInABox/Intro and the aia files for the projects in the book are here: http://www.appinventor.org/bookFiles

How to do a lot of basic things with App Inventor are described here: http://www.appinventor.org/content/howDoYou/eventHandling .

Also look here http://kio4.com/appinventor/index.htm and here http://www.imagnity.com/tutorial-index/ for more tutorials.

Learn about components http://ai2.appinventor.mit.edu/reference/components/

and visit the Library http://appinventor.mit.edu/explore/library

Try coding some Blocks, if you run into issues, return here and post what you tried and someone will provide specific advice.

Regards
Steve

3 Likes

thanks steve, still struggling with this but im trying to figure it out.
where do i find the event handler for the
"In a Button.Click event handler include the following

TextBox1.Text * 50 / TextBox2.Text = Label1.Text
"

Try this code snippet Neil Label2.Text = TextBox2.Text * 50 / TextBox3.Text all inside a Button10.Click.

You need a Button, a Label, and two TextBoxes and the appropriate Math Blocks.

The event handler is the Button.Click event Neil.

Did the example help?

1 Like

yes thats helped loads however on my one i cant seem to get the green textBox2.text to fit in the blue connector

ok now it just worked... im not sure what i did wrong

Great you got it working.

Just drag the TextBox object into the empty puzzle piece Neil. (The white space doesn't appear to be large enough but it is :slight_smile: Drag the piece with the knob fitting into the white 'nob' on the puzzle piece.

)

(notice, these Blocks have slightly different names than the original example)

yes lol i did that but it just wouldnt make the connector on the blue bit glow.... course soon as i said it wouldnt work... it worked!

Steve thank you I have my caculation part of my app now! I cant express my thanks enough.

Steve you are now credited for your help :slight_smile:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.