Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

take away digits..

Posted on 2014-04-15
9
Medium Priority
?
220 Views
Last Modified: 2014-04-15
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 ?
0
Comment
Question by:XK8ER
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40002977
e.g.

int x, y, z;

x = Convert.ToInt32(textBox1.Text);
y = Convert.ToInt32(textBox2.Text);
z = Convert.ToInt32(textBox3.Text);

x -= z;
y -= z;

textBox1.Text = x.ToString();
textBox2.Text = y.ToString();

Open in new window

0
 
LVL 23

Expert Comment

by:Michael Fowler
ID: 40002984
If it possible that either string is not a number then do not forget error handling when converting. Look at using TryParse

for example

int  x
bool result = Int32.TryParse(textBox1.Text, out x)
if (!result) {
   // do something to handle error
}

Open in new window


For more info look at
http://msdn.microsoft.com/en-us/library/f02979c7(v=vs.110).aspx

Michael
0
 
LVL 84

Accepted Solution

by:
David Johnson, CD, MVP earned 2000 total points
ID: 40003116
using System;
using System.Linq;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(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();
        }
    }
} 

Open in new window

After Pressing Calculate
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Closing Comment

by:XK8ER
ID: 40003120
thanks a lot!
0
 
LVL 84

Expert Comment

by:David Johnson, CD, MVP
ID: 40003133
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();
        }
    }
}

Open in new window

https://drive.google.com/file/d/0B542q8KsuQuEVjdpdHEzaF9fQ1E/edit?usp=sharing
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40003161
Interesting answer selection considering it's effectively a clone of my answer...
0
 
LVL 1

Author Comment

by:XK8ER
ID: 40003173
(z / 100);

is what I was looking for..
0
 
LVL 23

Expert Comment

by:Michael Fowler
ID: 40003183
XK8ER do not forget that if a non-numeric entry is made in the textbox then the code will throw an error
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40003207
Well, since you wrote:

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.
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Screencast - Getting to Know the Pipeline
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question