Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calculator 1

Status
Not open for further replies.

Flashoid

Technical User
Dec 11, 2002
163
US
Has anyone created a flash widget/calculator that I could repurpose? I need a form whereas the user enters 2 numbers and the formula/code can be adjusted based on the amounts they enter. If say the user enters 1000 units for the quantity ordered field and the actual quantity received field has 1050 entered, an if/then statement gives a result based on the % off between what the ordered and actual numbers are and assigns a numeric result which is displayed in the penalty field.

So if they are 0-3% off they are charged 0% penalty,
4% off a 1% penalty.. and so on up to a max of 8% penalty.
This % result would display in the Penalty field.

FORM:
enter quantity ordered_____ (input field)

enter quantity actually received___ (input field)

Submit (button)

Penalty__a %____field)
 
you could try this formula

Code:
guess = _root.quantityOrdered.text;
actual = _root.actualQuantityOrdered.text;
percent = Math.abs(guess-actual)/(actual)*100;
if ((percent>=0) && (percent<=3)) {
	_root.penalty.text = "1%";
} else if (percent<=4) {
	_root.penalty.text = "2%";
} else if (percent<=6) {
	_root.penalty.text = "3%";
} else if (percent<=8) {
	_root.penalty.text = "4%";
} else if (percent<=10) {
	_root.penalty.text = "5%";
} else if (percent<=12) {
	_root.penalty.text = "6%";
} else if (percent<=14) {
	_root.penalty.text = "7%";
} else if (percent<=16) {
	_root.penalty.text = "8%";
} else {
	_root.penalty.text = "Way Off!";
}

change those numbers to match the ranges you want

if you're putting this code on your main timeline, you might be able to change all those "if" statements to "switch" statements
 
thanks! I kinda new at this form thing. Would I create an
input text field and label it guess, and another labeled actual. Then create a dynamic text field labled results where the results text will display?
 
flashoid,
guess and actual are variables.

Code:
//.text refers to the text in the texbox
guess = _root.quantityOrdered.text;
actual = _root.actualQuantityOrdered.text;

name the instance name of your input boxes like this:

enter quantity ordered_____ (input field) = quantityOrdered

enter quantity actually received___ (input field) = actualQuantityOrdered

Penalty__a %____field) = penalty

sorry, i didnt see the Submit button on your first post, so on the actions for your submit button, put this code instead:

Code:
on (release) {
	guess = _root.quantityOrdered.text;
	actual = _root.actualQuantityOrdered.text;
	percent = Math.abs(guess-actual)/(actual)*100;
	if ((percent>=0) && (percent<=3)) {
		_root.penalty.text = "1%";
	} else if (percent<=4) {
		_root.penalty.text = "2%";
	} else if (percent<=6) {
		_root.penalty.text = "3%";
	} else if (percent<=8) {
		_root.penalty.text = "4%";
	} else if (percent<=10) {
		_root.penalty.text = "5%";
	} else if (percent<=12) {
		_root.penalty.text = "6%";
	} else if (percent<=14) {
		_root.penalty.text = "7%";
	} else if (percent<=16) {
		_root.penalty.text = "8%";
	} else {
		_root.penalty.text = "Way Off!";
	}
}

all i did was add the on(release) mouse event
 
benny2168;

Thanks a ton! It works great!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top