File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

If-Else help please

 
T Bart
Greenhorn
Posts: 5
IBM DB2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone tell me why this if-else statement will still allow values over 240 to be entered into my array? This is from a small project with a Swing GUI that allowsa user to enter a value into jTextArea1. When the user hits a button it evaluates the value using the below statement. If the user enters a value of 240 or greater, the message in the "else" statement is displayed as desired but the value still ends up in my array (myArray).

 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
T Bart wrote:...If the user enters a value of 240 or greater, the message in the "else" statement is displayed as desired but the value still ends up in my array...

Welcome to the Ranch!

If the "else" block is executing, then I don't see how the "if" block could. Is it possible you have another line of code somewhere that's adding the value to the array? What happens if you comment out the assignment (line 4) in the code you posted? Does the value still get added?
 
T Bart
Greenhorn
Posts: 5
IBM DB2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the quick reply! I thought that, too, about the statement. I remarked out the assignment part of the code and you are on the right track.The value still does end up getting entered into the array. I looked at every reference to myArray in my code and I can't see where the values would be getting added. Can you see anything? I'm posting the complete code.

 
Jason Koonce
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I think your code in lines 237 through 253 may be suspect. See if something there helps you get it in the right direction
 
T Bart
Greenhorn
Posts: 5
IBM DB2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's the section I originally posted. I remarked out the part that does the assignment to the array but the values still get added to the array. Is there something outside of that section that would be adding the values to the array as well? Weird!
 
T Bart
Greenhorn
Posts: 5
IBM DB2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found it. Lines 232 and 233 were outside the if-else statement and were adding to the total values without any evaluation. I moved those two lines of code to their respective places within each if-else statement and now everything is working properly. Thanks for your assistance!
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
T Bart wrote:I found it. Lines 232 and 233 were outside the if-else statement and were adding to the total values without any evaluation. I moved those two lines of code to their respective places within each if-else statement and now everything is working properly. Thanks for your assistance!

Ah... So it was adding to the cumulative value, but not to the array, right?
 
T Bart
Greenhorn
Posts: 5
IBM DB2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that is actually what was happening. When I would click the Run Report button, it would display the cumulative total which would include those invalid values.
 
kumarjit banerjee
Ranch Hand
Posts: 32
Eclipse IDE Oracle Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is your modified code




The portion which has been modified is indicated as //modified
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic