aspose file tools
The moose likes Beginning Java and the fly likes If-then conversion of textfields for calc Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "If-then conversion of textfields for calc" Watch "If-then conversion of textfields for calc" New topic
Author

If-then conversion of textfields for calc

Douglas TerBush
Greenhorn

Joined: Aug 27, 2002
Posts: 2
Here is the problem:
I have to convert information inputted into a textField to a variable format for calculations. I have to have error correction to ensure that information is inputted for each field. Further, I have two buttons and the problem is arrising in the calcButton section. I attempted to do this problem this way:
1st) Convert the three textField objects to String, and a double and double value.
2nd) Ran a test to ensure that the data in the variables contained information, if not give the appropriate error message.
3rd) Did the Calculations.
The problem is that the program attempts to convert empty information to a string or double without testing it first and I get errors.
I'm having a devil of a time nesting this dang thing properly. I know the problem is in the nesting of the if-else if statements and I can't see the code to fix it. Here is the example code, any suggestions?
[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ]
[ October 01, 2002: Message edited by: Dirk Schreckmann ]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Welcome to JavaRanch!
When posting code, please be sure to surround the code with the [code] and [/code] UBB Tags. This will help to preserve the formatting of the code, thus making it easier to read and understand.
Note that you can edit your own posts - just click on the icon that looks like a piece of paper.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Priya Mahale
Greenhorn

Joined: Sep 30, 2002
Posts: 4
Hi,
If the hoursWorked textfield is empty and u try to convert it into a double value then
double hoursWorked = new Double(hoursWorkedField.getText().trim()).doubleValue()
will definitely give u an exception..
Why dont u check whether the text fields r empty first??
If they r empty then give the appropriate error msg and if they r not empty then u can convert them to a double value.
i.e.,
String name = empNameField.getText();
String hrs = hoursWorkedField.getText;
and similarly for the 3rd text field.
if(name.length() == 0 )
{
// err msg;
}
if(hrs.length() == 0)
{
// err msg;
}
else
{
new Double(hoursWorkedField.getText().trim()).doubleValue();
}
and so on..
I really havent ran ur code and seen it so maybe what i have told might not be sufficient enough to debug ur code completely..
Anyway, hope this helps u
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: If-then conversion of textfields for calc
 
Similar Threads
payroll
Logic Errors
DUE AT MIDNIGHT TONIGHT..1 ERROR..HELP
Alright, my eyes hurt from staring at this monitor trying to figure this out.
Accepting Numeric User Input