• Post Reply Bookmark Topic Watch Topic
  • New Topic

is it possible to permanently change the value of a double variable by using an if statement?  RSS feed

 
Liam Rice
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is it possible to permanently change the value of a double variable by using an if statement? here is the code i have so far but it doesn't work. Any help please?



thank you
 
Dave Tolls
Ranch Foreman
Posts: 3056
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "it doesn't work"?
What result are you getting and what result are you expecting?
 
Liam Rice
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:What do you mean by "it doesn't work"?
What result are you getting and what result are you expecting?


well i want double EURtoGBP = 0.8482; to change to whatever the user inputs into changeEuro text field
 
Dave Tolls
Ranch Foreman
Posts: 3056
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK.
I suggest adding some logging in there, println() calls would do, to log what the value of everything is, and what path through that bit of code it takes.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liam Rice wrote:
well i want double EURtoGBP = 0.8482; to change to whatever the user inputs into changeEuro text field


From the code (ie. name of the method), I am going to speculate that there is a save button somewhere in the application. And that code that reads and sets the field is only executed when the button is pressed.... If I am wrong regarding this, then never mind ...

Anyway, you can place action listeners on text fields, so you can execute code, and hence, change variables, as soon as the user changes the fields. You still need to check it to make sure that the field is valid (and not blank), but this should not depend on the user pressing a button.

Henry
 
Liam Rice
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Liam Rice wrote:
well i want double EURtoGBP = 0.8482; to change to whatever the user inputs into changeEuro text field


From the code (ie. name of the method), I am going to speculate that there is a save button somewhere in the application. And that code that reads and sets the field is only executed when the button is pressed.... If I am wrong regarding this, then never mind ...

Anyway, you can place action listeners on text fields, so you can execute code, and hence, change variables, as soon as the user changes the fields. You still need to check it to make sure that the field is valid (and not blank), but this should not depend on the user pressing a button.

Henry


yes, this part of the program is for the admin to go to to change the exchange rate that the actual application uses within the calculation (to update). The user selects an exchange rate that they want to change, e.g. GBPtoUSD and they put in the updated exchange rate and then press save. At this point i am then wanting the user input to replace the GBPtoUSD once the save button is clicked
 
Knute Snortum
Sheriff
Posts: 4276
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have started the program in a way that you can see output to the command line (or a command box if in an IDE), put some debugging lines in the code, like:

Putting "// debug" after each line will help you find and remove the debugging lines after you don't need them.
 
Dave Tolls
Ranch Foreman
Posts: 3056
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd add one before the 'if' statement as well:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!