Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

take away digits..

Posted on 2014-04-15
9
Medium Priority
?
218 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 83

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
Python: Series & Data Frames With Pandas

Learn the basics of Python’s pandas library of series & data frames and how we can use these tools for data manipulation.

 
LVL 1

Author Closing Comment

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

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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

688 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