Solved

take away digits..

Posted on 2014-04-15
9
209 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 74

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:Michael74
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 78

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
 
LVL 1

Author Closing Comment

by:XK8ER
ID: 40003120
thanks a lot!
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 78

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 74

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:Michael74
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 74

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now