How to write scripts for buttons to perform arithmetic operations

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
WilliamCasey
Posts: 1
Joined: Thu Feb 29, 2024 12:13 pm
Contact:

How to write scripts for buttons to perform arithmetic operations

Post by WilliamCasey » Thu Feb 29, 2024 12:17 pm

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.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

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

Post by richmond62 » Thu Feb 29, 2024 12:53 pm

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
Attachments
CALC START.livecode.zip
(1.65 KiB) Downloaded 23 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

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

Post by richmond62 » Thu Feb 29, 2024 1:06 pm

LiveCode commands and syntax
Start with the supplied examples, and then start pooking around in the inbuilt Dictionary.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

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

Post by richmond62 » Thu Feb 29, 2024 1:17 pm

Traps an error if you try to divide something by zero:
-
SShot 2024-02-29 at 14.16.13.png
Attachments
CALC START 2.livecode.zip
(1.73 KiB) Downloaded 21 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

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

Post by richmond62 » Thu Feb 29, 2024 8:16 pm

Why do I feel that the OP might be a phantom?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9842
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

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

Post by FourthWorld » Thu Feb 29, 2024 11:28 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

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

Post by dunbarx » Fri Mar 01, 2024 4:23 pm

Richmond.

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


Craig

Post Reply

Return to “Android Deployment”