Solved

take away digits..

Posted on 2014-04-15
9
216 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 82

Accepted Solution

by:
David Johnson, CD, MVP earned 500 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
PowerShell Core for Advanced Linux Administrators

Understand advanced principals around Powershell Core with a focus on the Linux Administrator.  This course covers how to administer numerous environments across multiple platforms including Linux, Azure, AWS, and Google Cloud from a single shell instance.

 
LVL 1

Author Closing Comment

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

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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

624 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