This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

more math stuff  RSS feed

 
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?
 
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?
 
lowercase baba
Bartender
Posts: 12627
50
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.
 
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!