?
Solved

checking for no value

Posted on 2006-05-17
3
Medium Priority
?
158 Views
Last Modified: 2010-04-01
I have a small snippett of coding that is confusing me.
I want to check to make sure the sqty and ssell have values and are not empty
It phews big time and I do not know why. It does not the comparsion and does not like my error message to the user..:((
How would I check to ensure it is numeric??
Can someone please help me??

sqty = new Integer(request.getParameter("soldqty"))
ssell = new Float(request.getParameter("sellprice"));
        
 if (sqty != 0  &&  ssell != 0 ) {
     stot1 = new Float(sqty.intValue()*ssell.floatValue());
   }
ese{       
     string verr = "SOLD PRICE OR SOLD QUANTITY INVALID";
     out.println(verr);
     }
0
Comment
Question by:bearpaws
  • 2
3 Comments
 
LVL 28

Accepted Solution

by:
rrz earned 800 total points
ID: 16705676
You could use something like the following.
<%
String soldqty = request.getParameter("soldqty");
String sellprice = request.getParameter("sellprice");
if(soldqty != null && sellprice != null){
             try{
                    int sqty = Integer.parseInt(soldqty);
                    float ssell = Float.parseFloat(sellprice);
                    float stot1 = ssell * sqty;
                  } catch(NumberFormatException nfe){
                                      out.println("SOLD PRICE OR SOLD QUANTITY INVALID");
                    }
}else {
       out.println("SOLD PRICE OR SOLD QUANTITY NOT SENT");
      }
%>
0
 

Author Comment

by:bearpaws
ID: 16710892
that worked pretty good!
When I print a line using out.println, All my error messages end on the same line.
I thought you used out.newlin() to skip down a line.
Could you clarify that point for me??
thank you again
0
 

Author Comment

by:bearpaws
ID: 16711013
I figured it out!
thanks!
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
Tech giants such as Amazon and Google have sold Alexa and Echo to such an extent that they have become household names. And soon they are expected to be used by commoners in their homes, ordering takeout, picking out a song, answering trivia questio…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question