• Post Reply Bookmark Topic Watch Topic
  • New Topic

more math stuff  RSS feed

 
Adrienne Peck
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hope the saloon hands are not tired of my math questions...

i have a string that needs to be incremented by one. i am getting compiler errors with this code:
bpt.Current_Billing_Year_2 = (++Integer.toString(Integer.parseInt(bpt.Current_Billing_Year_2)));

actually, i have put the increment signs (++) in every place on the right side of the equation that is possible. each generates a compiler error.
of course it doesn't work to increment the string so my question is...what in the world do i increment?
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are trying to increament the String not the int
try:
 
Adrienne Peck
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the help! that makes sense. i made the change but am getting a message that states 'invalid argument to operation' with this code:

(bpt.Current_Billing_Year_2) = (Integer.toString(++(Integer.parseInt(bpt.Current_Billing_Year_2))))

the left side of the equation is a string. when i parse it to be an integer, i get an error saying the left-hand side must be a variable. i think i'm missing something basic here...

wouldn't '(bpt.Current_Billing_Year_2)' be considered a variable?
why would i still get 'invalid argument to operation' error when i am incrementing the parsed integer value and not the string?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ugg...

don't put all the code on one line. it makes it hard to figure out what's going on, hard to read, hard to debug, and hard to correct.

one line of code should do one thing (in my opinion).

parse the string on one line, and save it in a temp variable. make sure that works. then increment it. then convert that back to a string.

even if you don't want to do that in your production code (although i'd still reccomend you DO), do it to test stuff and see what's going on.
 
Adrienne Peck
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, thanks...it worked. I've learned two lessons today - how to code and how to format better.
 
Benjamin Lau
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by fred rosenberger:
don't put all the code on one line. it makes it hard to figure out what's going on, hard to read, hard to debug, and hard to correct.

one line of code should do one thing (in my opinion).


Thanks! I got a lot.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!