Click here to Skip to main content
15,894,740 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

Yes - just handle the TextChanged event for the textbox, and set the value of the other one.
C#
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.
 
Share this answer
 
Comments
[no name] 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 12-Jan-13 11:23am    
Then you need to specify your goal seeking conditions...am I supposed to read your mind? :laugh:
Can be done easily with TextChanged event and autopostback in text box

XML
<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


C#
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();
    }
}
 
Share this answer
 
this is the code

C#
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();
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900