Hello, LiveCode specialists.
I'm working on a project that includes constructing a simple calculator app with LiveCode. I followed the tutorial and successfully created a basic interface with buttons and fields. However, I am unsure how to build the script for the buttons to conduct the arithmetic calculations. I looked through the LiveCode docs and forums, but I couldn't find a clear example or explanation for how to achieve this.
How can I create a script for the calculator buttons that performs addition, subtraction, multiplication, and division on the numbers entered into the fields? What LiveCode commands and syntax do I need to use? How do I deal with problems like dividing by zero or entering invalid input?
I would appreciate any assistance or advice on how to resolve this issue.
How to create scripts for buttons that execute arithmetic operations
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- VIP Livecode Opensource Backer
- Posts: 9785
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: How to create scripts for buttons that execute arithmetic operations
Hi, Welcome to LC and this forum.
Here is a simple stack. Check out the scripts of the "+" button, the "clear" button and the two top fields. This should be enough to finish your app.
Craig
Here is a simple stack. Check out the scripts of the "+" button, the "clear" button and the two top fields. This should be enough to finish your app.
Craig
-
- VIP Livecode Opensource Backer
- Posts: 9785
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: How to create scripts for buttons that execute arithmetic operations
Just read your post again.
When you have mastered the sample stack, the answer to your other questions will become pertinent. Write back at that time and we can go through the MANY small tweaks that a reliable calculator should have, like entry validation. It would not be good if the user tried to add 42 to "chicken".
Craig
When you have mastered the sample stack, the answer to your other questions will become pertinent. Write back at that time and we can go through the MANY small tweaks that a reliable calculator should have, like entry validation. It would not be good if the user tried to add 42 to "chicken".
Craig
-
- VIP Livecode Opensource Backer
- Posts: 9785
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: How to create scripts for buttons that execute arithmetic operations
Me again. I am not sure how your app is built. For example, if it contains only buttons with numbers labelled on them, and other buttons that only, say, add, there is no need for entry validation. But you yourself raised that point, so perhaps your calculator asks the user to enter numbers, and then the issue could arise.
All this is to make you think about what you are building, and how it will work, entirely apart from the tools in LC you need to make it happen.
Craig
All this is to make you think about what you are building, and how it will work, entirely apart from the tools in LC you need to make it happen.
Craig
-
- VIP Livecode Opensource Backer
- Posts: 9867
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: How to create scripts for buttons that execute arithmetic operations
There are dozens of tutorials. Did you see the one for making a calculator?tetroup wrote: ↑Thu May 23, 2024 10:28 amI'm working on a project that includes constructing a simple calculator app with LiveCode. I followed the tutorial and successfully created a basic interface with buttons and fields. However, I am unsure how to build the script for the buttons to conduct the arithmetic calculations.
https://livecode.com/lessons/calculator/
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- VIP Livecode Opensource Backer
- Posts: 9785
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: How to create scripts for buttons that execute arithmetic operations
Richard.
The OP mentioned following a tutorial, though not which one. I suspect that since entry validation was mentioned early on, that the "calculator" is more home-brewed than the ordinary tutorial version.
Craig
The OP mentioned following a tutorial, though not which one. I suspect that since entry validation was mentioned early on, that the "calculator" is more home-brewed than the ordinary tutorial version.
Craig