1 Reply Latest reply on Jun 9, 2012 3:47 PM by Rod@FOF

    Basic calculator


      Can anybody give me some help with creating a Basic calculator using Lingo with Local and Global variables.


      I'm having problems displaying numbers with more than one digit.



        • 1. Re: Basic calculator
          Rod@FOF Level 1

          Nobody as offered any response, so here's a start for you.


          Open your "message" window, found under the "Windows" tab. In the white area at top of screen type: put 7.0 + 4.1. In the bottom pane, you will see the answer. Now type: put 8.4* 6.1. Again, in the bottom pane you will see the answer.


          Now, think about how you could make these operations occur on your screen without the message window. First you will need a keypad. The keypad must contain numbers and operators. And clicking on each key must place the values in a sequence not unlike the "puts" above. the only difference is, rather than doing a "put" you set the result to a variable name, for example, call the output "result." You can also try this in your message window to see how it would work. Try this. result = (2.4 + 5.1 - 22.0 / 2.3). Nothing will appear in the bottom pane of the message window, but if you now type put result, it will appear. So, imagine this. You have a series of keys that you click on that include numbers and operators and they produce a statement similar to the result value above. Now, when you click the "equal" key on your keypad, it generates the "result" and puts it into a sprite on your calculator named "result" for example, sprite("result").member.text = string(result).


          As far as displaying numbers with more than one digit, if you can't ge past this, you are probably in deeeeeeep trouble. For example, a field member can take any text input you want to put in it. Say, for example, member("result").text = "22.4". This text can become a number just by declaring it: Answer = float(member("result").text. And just as quickly become something put into a field by saying, for example, sprite("result").member. text  = string(Answer). Thist takes Answer and coverts it back to text that can go into the sprite on the string.


          Hopefully, this is of some help. Actually generating a calculator is mostly a simple task. If you can do it for two sprites, you just repeat the same process over and over again.