Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I have a textbox1( value int 10000) and a textbox2 ( value double 1.45). I want to decrease textbox1 value every second with the textbox2 value (10000, 9998.45, 9997.1 etc)

What I have tried:

Tried to set timer tick but nothing
Posted
Updated 23-Jul-20 5:12am
Comments
anakinche 23-Jul-20 11:50am    
I am sorry .I use c#
Richard MacCutchan 23-Jul-20 12:15pm    
"textbox1( value int 10000) and a textbox2 ( value double 1.45)"
TextBoxes do not contain values, they contain strings. Those strings need to be converted to int and float respectively (via the TryParse methods) before you can use them in calculations.

1 solution

OK, we don't know what language you are using, or even framework - let alone environment - so there are a massive number of possible answers to this, and we can't give you any "specific" solution. For example, a PHP/Javascript web based solution would be very different from a C# WinForms solution.

But we can kinda explain the basics.
Start with the timer: read the documentation for your language / framework / environment for "timers" and look at the code samples.
These may be a starting point:
JavaScript Timing Events[^]
Timer Class (System.Timers) | Microsoft Docs[^]

Then you need to do three things:
1) Validate and convert the textbox1 content to a double
2) Validate and convert the textbox2 content to a double
3) Subtract one from the other and put the result back into textbox1

Again, they may be a starting point:
JavaScript parseFloat() Function[^]
Double.TryParse Method (System) | Microsoft Docs[^]

Note that you can't convert textbox1 to an integer, as it will fail and ignore the fractional part of the textbox2 value anyway.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900