Page 1 of 1

How to write scripts for buttons to perform arithmetic operations

Posted: Thu Feb 29, 2024 12:17 pm
by WilliamCasey
Hello LiveCode experts,

I am working on a project that involves creating a simple calculator app using LiveCode. I have followed the tutorial and managed to create a basic interface with buttons and fields. However, I am stuck on how to write the script for the buttons to perform the arithmetic operations. I have searched the LiveCode documentation and forums, but I could not find a clear example or explanation of how to do this.

How can I write a script for the calculator buttons to perform the addition, subtraction, multiplication, and division operations on the numbers entered in the fields? What are the LiveCode commands and syntax that I need to use? How can I handle errors such as dividing by zero or entering invalid input?

I would appreciate any help or guidance on how to solve this problem.

Re: How to write scripts for buttons to perform arithmetic operations

Posted: Thu Feb 29, 2024 12:53 pm
by richmond62
I have a feeling that you should be doing some of the work.

Here is "something" to get you started (it involved about 10 minutes work, so do NOT expect anything very special):
-
SShot 2024-02-29 at 13.51.49.png

Re: How to write scripts for buttons to perform arithmetic operations

Posted: Thu Feb 29, 2024 1:06 pm
by richmond62
LiveCode commands and syntax
Start with the supplied examples, and then start pooking around in the inbuilt Dictionary.

Re: How to write scripts for buttons to perform arithmetic operations

Posted: Thu Feb 29, 2024 1:17 pm
by richmond62
Traps an error if you try to divide something by zero:
-
SShot 2024-02-29 at 14.16.13.png

Re: How to write scripts for buttons to perform arithmetic operations

Posted: Thu Feb 29, 2024 8:16 pm
by richmond62
Why do I feel that the OP might be a phantom?

Re: How to write scripts for buttons to perform arithmetic operations

Posted: Thu Feb 29, 2024 11:28 pm
by FourthWorld
richmond62 wrote:
Thu Feb 29, 2024 8:16 pm
Why do I feel that the OP might be a phantom?
I can't imagine how you could get that impression. It's been less than a day since he posted his question.

Re: How to write scripts for buttons to perform arithmetic operations

Posted: Fri Mar 01, 2024 4:23 pm
by dunbarx
Richmond.

Your rate of posting has unsettled your expectations. :wink:


Craig