Number entered by a user which works out percentages
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Number entered by a user which works out percentages
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.
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.
-
- Livecode Opensource Backer
- Posts: 447
- Joined: Mon Jan 23, 2012 12:46 pm
Re: Number entered by a user which works out percentages
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:
4. Put this script in your "clear" button:
5. Test it out.
This is a very simplified version of a tip calculator
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
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
Code: Select all
on mouseUp
repeat with x = 1 to 4
put empty into fld x
end repeat
end mouseUp
This is a very simplified version of a tip calculator

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
Re: Number entered by a user which works out percentages
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.!
I will for sure check out the link.
Thank you again.!
-
- Livecode Opensource Backer
- Posts: 447
- Joined: Mon Jan 23, 2012 12:46 pm
Re: Number entered by a user which works out percentages
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
Welcome!
--Sefro
Re: Number entered by a user which works out percentages
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.!
This list of related sites will be very helpful too.
Thanks again.!
Re: Number entered by a user which works out percentages
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
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
Re: Number entered by a user which works out percentages
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
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
Re: Number entered by a user which works out percentages
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.!
Re: Number entered by a user which works out percentages
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
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
Re: Number entered by a user which works out percentages
Hey Craig,
You left out the Fun!
Simon
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!
Re: Number entered by a user which works out percentages
Damn, Simon.
Getting old and crotchety.
Craig
Getting old and crotchety.
Craig
Last edited by dunbarx on Tue Jul 15, 2014 2:16 am, edited 1 time in total.
Re: Number entered by a user which works out percentages
lol thanks guys.!