Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

How to check a text field

Options
  • 06-12-2004 2:15pm
    #1
    Registered Users Posts: 488 ✭✭


    I want to check to see if the data entered in a text field is a double..if it is i want to write to the file..if it is a string den i want the program to catch the error and not write any data to the file.

    at the moment this is what i have written

    try{
    setMinimumLevel((double)makeDouble(minimumLevelField.getText()));
    }
    catch(NumberFormatException exp)
    {
    stockMinimumLevelField.setText("");
    a = ("Please enter double in Minimum Level. ");
    }

    how can i check on this line
    setMinimumLevel((double)makeDouble(minimumLevelField.getText()));


Comments

  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    C++, C#, Java, none of the above?


  • Registered Users Posts: 488 ✭✭lad12


    sorry java


  • Registered Users Posts: 3,312 ✭✭✭mr_angry


    IIRC there's an "IsDouble()" method on the double class itself.

    I could be wrong though.


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    If you can, use Double.parseDouble(String s) which will return a double value to you.

    But, as I suspect that this is an assiagnment on method writing more than anything else, just return the double value back out. If an exception this thrown, you'll jump to that, but if not just continue to write the value to file.


  • Closed Accounts Posts: 7,230 ✭✭✭scojones


    Go to http://www.javadoconline.com and search for "java.lang.Double". Happy reading.


  • Advertisement
  • Registered Users Posts: 488 ✭✭lad12


    But, as I suspect that this is an assiagnment on method writing more than anything else, just return the double value back out. If an exception this thrown, you'll jump to that, but if not just continue to write the value to file

    I already have created a method called make double..this changes the text to a double..but i want to check to see if 4 of the text fields are doubles..if they aint then i dont want to write anything to the file..how can i exit after the exception has been caught without exiting the program altogether.
    I created a blank method(blanks the text fields) so i can call this when the exception is caught but it writes 0's to the file.


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    Ok, here are a few hints... Boolean returns, if, loop.


  • Closed Accounts Posts: 7,230 ✭✭✭scojones




  • Registered Users Posts: 27,163 ✭✭✭✭GreeBo


    lad12 wrote:
    I already have created a method called make double..this changes the text to a double..but i want to check to see if 4 of the text fields are doubles..if they aint then i dont want to write anything to the file..how can i exit after the exception has been caught without exiting the program altogether.
    I created a blank method(blanks the text fields) so i can call this when the exception is caught but it writes 0's to the file.
    so you want to loop 4 times while some check is true
    if its false then you want to stop and set an error message

    Always try to think these things out in your head first and then "just" code it..


Advertisement