BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 09-06-2010, 07:53 AM   #1 (permalink)
New Member
 
Join Date: Sep 2010
Location: Canada
Model: 8330
PIN: N/A
Carrier: Telus
Posts: 10
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Help needed to create Numeric Fields & Calculations

Please Login to Remove!

Hi I'm a newbie needing some help with some coding

I am building an application that will enable me to quickly calculate mark-up on inventory items.

I have created a lookup table containing basic information about the various product packaging and their content quantities, and an edit field to record the name of the item. I'm having problems though creating fields to hold numeric values and for the respective calculations.

I need some assistance to create fields that will enable me to enter numeric values and to calculate the Mark-up and Selling Price....

The numeric fields I am in need of are as follows: Cost Price: ($000.00); Mark-up Percentage: (00.0000%) Mark-up: ($000.00.....ie Cost Price x Mark-up %); Selling Price: ($000.00......ie Cost Price + Mark-up).

I would sincerely appreciate any assistance with this coding as I really don't know what to do. Thanks!
Offline  
Old 09-09-2010, 10:21 AM   #2 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2010
Model: 8530
PIN: N/A
Carrier: Sprint
Posts: 48
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

you need similar code as below: you can use double/float instead of int.

Code:
BasicEditField first= new BasicEditField("First:  ", "", 5, 0) ;
add(first);
BasicEditField second= new BasicEditField("Second:  ", "", 5, 0);
add(second);

ButtonField calButton = new ButtonField("Calculate Sum", ButtonField.CONSUME_CLICK);
calButton.setChangeListener(this);
add(calButton);

public void fieldChanged(Field field, int context) {
		if (calButton == field) {
int a=Integer.parseInt(first.getText());
int b=Integer.parseInt(second.getText());
int r=a+b;
add(new LabelField("Result : " + r));
	}
}
Offline  
Old 09-10-2010, 09:49 AM   #3 (permalink)
New Member
 
RockoAndy's Avatar
 
Join Date: Sep 2010
Model: 8900
PIN: N/A
Carrier: Airtel
Posts: 11
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Alex,

It would be better if u use filters for the basic edit field not doing so will cause number format exception when u enter text instead of numbers...

Code:
new BasicEditField("First:  ", "0", 5, BasicEditField.FILTER_NUMERIC);
__________________
the amazing world of
Offline  
Old 09-10-2010, 09:57 AM   #4 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2010
Model: 8530
PIN: N/A
Carrier: Sprint
Posts: 48
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, RockoAndy is right. It will be better to use filters...
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.