XK8ER
asked on
take away digits..
hello,
I have inside a textbox a number "10"
I have two string one with "16523"
and another one with "1188"
based on the textbox how can I take away 10 from the first string to display "16513"
and take away 10 from second string displaying like this "1187.9"
maybe with String.Format ?
I have inside a textbox a number "10"
I have two string one with "16523"
and another one with "1188"
based on the textbox how can I take away 10 from the first string to display "16513"
and take away 10 from second string displaying like this "1187.9"
maybe with String.Format ?
If it possible that either string is not a number then do not forget error handling when converting. Look at using TryParse
for example
For more info look at
http://msdn.microsoft.com/en-us/library/f02979c7(v=vs.110).aspx
Michael
for example
int x
bool result = Int32.TryParse(textBox1.Text, out x)
if (!result) {
// do something to handle error
}
For more info look at
http://msdn.microsoft.com/en-us/library/f02979c7(v=vs.110).aspx
Michael
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks a lot!
using the onchange event
using System;
using System.Linq;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
double x, y, z;
x = Convert.ToDouble(textBox1.Text);
y = Convert.ToDouble(textBox2.Text);
z = Convert.ToDouble(textBox3.Text);
x -= z;
y -= (z / 100);
textBox1.Text = x.ToString();
textBox2.Text = y.ToString();
}
}
}
https://drive.google.com/file/d/0B542q8KsuQuEVjdpdHEzaF9fQ1E/edit?usp=sharing
Interesting answer selection considering it's effectively a clone of my answer...
ASKER
(z / 100);
is what I was looking for..
is what I was looking for..
XK8ER do not forget that if a non-numeric entry is made in the textbox then the code will throw an error
Well, since you wrote:
...instead of:
...I'm sure you can appreciate why it was unclear what you wanted. Oh well.
and take away 10 from second string displaying like this "1187.9"
...instead of:
and take away .10 from second string displaying like this "1187.9"
...I'm sure you can appreciate why it was unclear what you wanted. Oh well.
Open in new window