Number entered by a user which works out percentages

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
StuartJD
Posts: 6
Joined: Sat Jul 12, 2014 4:04 pm

Number entered by a user which works out percentages

Post by StuartJD » Sat Jul 12, 2014 4:14 pm

Hi all, brand new to this so please excuse me if this is a very basic question.
I would like to know how to code for the following simple little project. I would like the user to enter a number into a text field (max of 7 numbers) which will automatically work out certain percentages i.e. 5%, 10%, 15% and 20% and show these answers in separate fields shown underneath the number entered by the user.
I've tried looking through the forums, but not sure the correct terminology to use.

Thanks in advance.

sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Re: Number entered by a user which works out percentages

Post by sefrojones » Sat Jul 12, 2014 4:41 pm

This should get you started on your way:

1. Create a New stack

2. Drag out 2 buttons, and four fields. Name the Buttons "Get Percentage" and "Clear"

3.Put this script in your "Get Percentage" button:

Code: Select all

on mouseUp
   ask "Enter Number"
   put it into tNumber
   put tNumber * .05 into fld 1
   put tNumber * .1 into fld 2
   put tNumber * .15 into fld 3
   put tNumber * .2 into fld 4
   
end mouseUp
4. Put this script in your "clear" button:

Code: Select all

on mouseUp
   repeat with x = 1 to 4
      put empty into fld x
   end repeat
end mouseUp
5. Test it out.

This is a very simplified version of a tip calculator :D

edit: This script does not limit your number entry to 7 digits, but I think it will at least get you started on your way. I HIGHLY recommend you check out the Scripting Conference stacks from here:
http://www.hyperactivesw.com/revscriptc ... ences.html

StuartJD
Posts: 6
Joined: Sat Jul 12, 2014 4:04 pm

Re: Number entered by a user which works out percentages

Post by StuartJD » Sat Jul 12, 2014 4:54 pm

Hi, thank you so much for the fast response. I did have a look at the calculator sample. I started to vaguely understand but was struggling. I will look at your code and I am sure it will make more sense as I look through it.
I will for sure check out the link.
Thank you again.!

sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Re: Number entered by a user which works out percentages

Post by sefrojones » Sat Jul 12, 2014 5:07 pm

No problem at all. I'm sure you'll quickly see what is going on in the example above. this list of livecode related sites might also help. There's tons of info and tutorials around, sometimes they're not exactly easy to find. I think between the scripting conference stacks and the list I just gave you, you should be up and running in no time! There is also a User Guide, which you may or may not know can be accessed through the help menu in the IDE. This forum is also a great place to get help and ask questions.

Welcome!
--Sefro

StuartJD
Posts: 6
Joined: Sat Jul 12, 2014 4:04 pm

Re: Number entered by a user which works out percentages

Post by StuartJD » Sat Jul 12, 2014 6:22 pm

Hi Sefro, yes, your example once I implement it, I can see how it works and have tweaked it around some more, so I guess that does mean I am grasping it.! lol
This list of related sites will be very helpful too.
Thanks again.!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10333
Joined: Wed May 06, 2009 2:28 pm

Re: Number entered by a user which works out percentages

Post by dunbarx » Sat Jul 12, 2014 8:20 pm

Stuart.

Welcome to LC and this forum. Do read the user manual and peruse the lessons. Write to us at any time with problems and frustrations. We do not wish to teach you LC, but will respond with infinite patience with your questions and complaints.

You have chosen a perfect project to start. Please do the following: tweak, as you say. Then add functionality of any and all kinds you can think of, especially things which are utterly useless to you, but you think you can implement. Throw them out later, if you want, but the exercise of making them work will be the best way for you to learn how to drive.

Craig Newman

StuartJD
Posts: 6
Joined: Sat Jul 12, 2014 4:04 pm

Re: Number entered by a user which works out percentages

Post by StuartJD » Sat Jul 12, 2014 11:50 pm

Hi Craig, thank you, and yes, I have every intention of going through as many tutorials as I can get my hands on.

Yes, that was my plan to start on something pretty easy and build on it through what I will learn through the lessons.


Thanks again.
Stuart

StuartJD
Posts: 6
Joined: Sat Jul 12, 2014 4:04 pm

Re: Number entered by a user which works out percentages

Post by StuartJD » Sun Jul 13, 2014 7:36 am

Ok, now I feel a bit silly, I have just been through some of the tutorials in the lists and found exactly my question, even down to the percentages being the same.!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10333
Joined: Wed May 06, 2009 2:28 pm

Re: Number entered by a user which works out percentages

Post by dunbarx » Sun Jul 13, 2014 2:55 pm

Good.

Now create a handful of completely spurious and useless enhancements to your already working stack. At this stage in your life, you need lots, and I do mean lots of ancillary programming exercises, and it matters not if these are ultimately useful. The work, and the failure, and the triumph is the point.

Did I mention the work?

Craig

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Number entered by a user which works out percentages

Post by Simon » Sun Jul 13, 2014 3:35 pm

Hey Craig,
You left out the Fun!

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10333
Joined: Wed May 06, 2009 2:28 pm

Re: Number entered by a user which works out percentages

Post by dunbarx » Sun Jul 13, 2014 3:47 pm

Damn, Simon.

Getting old and crotchety.

Craig
Last edited by dunbarx on Tue Jul 15, 2014 2:16 am, edited 1 time in total.

StuartJD
Posts: 6
Joined: Sat Jul 12, 2014 4:04 pm

Re: Number entered by a user which works out percentages

Post by StuartJD » Mon Jul 14, 2014 10:13 pm

lol thanks guys.!

Post Reply