A Little Mathematics

Hyperstudio takes on new functionality when you add a little programming to it. Behind the scene, as we've seen before is a whole scripting language called Hyperlogo. In this case, we're going to create a stack that lets the user enter a couple of numbers and we'll ask Hyperstudio to add them together and display the results.

We'll start with a new stack. In the stack, create two text boxes and place them appropriately on the screen. In the example below, I've created the two boxes, made sure that the border is visible and have turned off scroll bars and the ability for the field to be scrollable.

So far, so good.

Let's add a third field to display the answer. It's just another text box.

As you know, all boxes on the field require names. I named them "Number1", "Number2", and "Answer" so that the fields make sense to me. Shortly, the field names will be really important.

The Programming Part.

This is where it gets exciting. As you can see above, I've created a button and added the text "Add two numbers". When the button is pressed, we're going to use Hyperlogo. The actual script that performs this action is listed below.

You should recognize the fields from the Hyperstudio stack. "Number1", "Number2", and "Answer".

In order for Hyperlogo to do the calculations, we have to be able to take the information from the Hyperstudio boxes and assign them to variables, or placeholders, so that Hyperlogo can work its magic. There are some key words that help out. "Make", and "GetFieldText []" literally say "Take whatever number is in the Hyperstudio field 'Number1' and call it 'FirstNumber'. Ditto for 'SecondNumber'.

The final step is to add the two numbers together (see the + sign), take the result and the "SetFieldText []" key word instructs Hyperlogo to take the result and put it into Hyperstudio field called "Answer". Variables in Hyperlogo are always preceded by a :.

And, that's it!

As they say in textbooks, the reader is left to develop upon the ideas. How about adding programming to make this a fully functional calculator. You've already got the two input fields, and an output field. All that you need to do is add a button and logic to do the subtracting, multiplying, and dividing.

You're probably thinking -- great, Doug. We take a $1400 computer, add a piece of software, put in some time and effort and we get a calculator that does the same thing as what many people carry on a key chain.

Right...partially. While this example is a simple calculator, it does introduce the student to the concept of programming. Who knows, the next great programmer may be sitting in your class and get excited about this. In addition, extend this to a number of routine calculations and have the students make custom applications. Or, consider the Multimedia Festival and see who can design the most funky looking calculator. Or, ...

The possibilities are endless!

 

2 3 4 5 6 7 8 9 10 11 12