Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0
I need to develop an application
where Goal seek function need to be implemented for percentage calculation.
 
Like
A1     b1   c1   d1
2000   4    80  2080
when I change the d1 cell value
A1 cell value should get changed in excel using goal seek.
 
Same concept need to be implemented in C#
textbox1  textbox2  textbox3   textBox4   
 2000      4         80          2080      
If I change textbox4 then textbox1 and textbox3 would get change
 
Is it possible?
 
If yes then please help
Posted 12-Jan-13 5:11am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Yes - just handle the TextChanged event for the textbox, and set the value of the other one.
textbox1.Text = (int.Parse(textbox4.Text) - int.Parse(textbox3.Text)).ToString();
Clearly, you will want to put checking in there to make sure the boxes are numeric, and so forth.
  Permalink  
Comments
Sourav Sarkar-SS2 at 12-Jan-13 11:17am
   
you didn't got my question
textbox1 textbox2 textbox3 textBox4
2000 4 80 2080
If I change textbox4 to 3000, then it will be automatically
2884.615385 4 115.3846154 3000
OriginalGriff at 12-Jan-13 11:23am
   
Then you need to specify your goal seeking conditions...am I supposed to read your mind? :laugh:
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Can be done easily with TextChanged event and autopostback in text box
 
<form runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
  <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
  <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
  <asp:TextBox ID="TextBox4" runat="server" ontextchanged="TextBox4_TextChanged"
      style="height: 22px" AutoPostBack=true></asp:TextBox>
  </form>

 
and the cs coding
 

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        TextBox3.Text = "0";
 

    }
 

 
    protected void TextBox4_TextChanged(object sender, EventArgs e)
    {
     TextBox1.Text = (int.Parse(TextBox4.Text)- int.Parse(TextBox3.Text)).ToString();
    }
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

this is the code
 
double a, b, c,v,d;
           bool x = double.TryParse(textBox2.Text, out a);
           b = (a / 100) + 1;
           x = double.TryParse(textBox1.Text, out v);
           c = v / b;
           d = c * a / 100;
           c = Math.Round(c, 2);
           d = Math.Round(d, 2);
           textBox3.Text = c.ToString();
           textBox4.Text = d.ToString();
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 150
2 PIEBALDconsult 110
3 Richard MacCutchan 105
4 Sergey Alexandrovich Kryukov 104
0 OriginalGriff 6,055
1 DamithSL 4,621
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,500
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 12 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100