problem with equasion

Hello, I've got problem with my code. The results of equasion are weird and the same for any value I tipe in edit. Please help. It's in c++ builder 6, and unfortunatly I have to do this in borland.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
  //---------------------------------------------------------------------------
#include <cstring>
#include <vcl.h>
#pragma hdrstop
#include <math.h>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;

double R1, R2, R3, R4, R5, R6, E1, E2, E3, Io1, Io2, Io3,
I1, I2, I3, I4, I5, I6, W1, W2, W3, WR;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
         double R1 = StrToFloat(Edit1->Text);
         double R2 = StrToFloat(Edit2->Text);
         double R3 = StrToFloat(Edit3->Text);
         double R4 = StrToFloat(Edit4->Text);
         double R5 = StrToFloat(Edit5->Text);
         double R6 = StrToFloat(Edit6->Text);
         double E1 = StrToFloat(Edit7->Text);
         double E2 = StrToFloat(Edit8->Text);
         double E3 = StrToFloat(Edit9->Text);

	WR = (((R1+R2+R5)*(R2+R3+R6)*(R1+R3+R4))-(R2*R3*R1)-(R1*R2*R3))-((R1*(R2+R3+R6)*R1)+((R1+R2+R5)*R3*R3)+(R2*R2*(R1+R3+R4)));

	W1 = (((E1-E2)*(R2+R3+R6)*(R1+R3+R4))+(R2*R3*E3)+(R1*E2*R3))-(((E1-E2)*R3*R3)-(R1*(R2+R3+R6)*E3)+(R2*E2*(R1+R3+R4)));

	W2 = (((R1+R2+R5)*E2*(R1+R3+R4))+((E1-E2)*R3*R1)+(R1*R2*E3))-((R1*E2*R1)-(E3*R3*(R1+R2+R5))-((E1-E2)*R2*(R1+R3+R4)));

	W3 = (((R1+R2+R5)*(R2+R3+R6)*E3)+(R2*E2*R1)+((E1-E2)*R2*R3))-((R2*R2*E3)-((E1-E2)*(R2+R3+R6)*R1)-((R1+R2+R5)*E2*R3));


        Io1 = W1/WR;

        Io2 = W2/WR;

        Io3 = W3/WR;

         I1 = Io1-Io3;
         I2 = Io1-Io2;
         I3 = Io3-Io2;
         I4 = Io3;
         I5 = Io1;
         I6 = Io2;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
        Label2->Caption="I1=";
        Label3->Caption="I2=";
        Label4->Caption="I3=";
        Label5->Caption="I4=";
        Label6->Caption="I5=";
        Label7->Caption="I6=";
        Label8->Visible=false;
        Label9->Visible=false;
        Label10->Visible=false;
        Label11->Visible=false;
        Label12->Visible=false;
        Label13->Visible=false;
        Button1->Visible=false;
        Edit7->Visible=false;
        Edit8->Visible=false;
        Edit9->Visible=false;
        Button2->Visible=1;
        Edit1->Text = FloatToStr(I1);
        Edit2->Text = FloatToStr(I2);
        Edit3->Text = FloatToStr(I3);
        Edit4->Text = FloatToStr(I4);
        Edit5->Text = FloatToStr(I5);
        Edit6->Text = FloatToStr(I6);





}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
        Label2->Caption="R1=";
        Label3->Caption="R2=";
        Label4->Caption="R3=";
        Label5->Caption="R4=";
        Label6->Caption="R5=";
        Label7->Caption="R6=";
        Label8->Visible=1;
        Label9->Visible=1;
        Label10->Visible=1;
        Label11->Visible=1;
        Label12->Visible=1;
        Label13->Visible=1;
        Button1->Visible=1;
        Edit7->Visible=1;
        Edit8->Visible=1;
        Edit9->Visible=1;
        Button2->Visible=0;
        Edit1->Text="";
        Edit2->Text="";
        Edit3->Text="";
        Edit4->Text="";
        Edit5->Text="";
        Edit6->Text="";
        Edit7->Text="";
        Edit8->Text="";
        Edit9->Text="";

}
//--------------------------------------------------------------------------- 
Last edited on
print out
double R1 = StrToFloat(Edit1->Text);
double R2 = StrToFloat(Edit2->Text);
double R3 = StrToFloat(Edit3->Text);
double R4 = StrToFloat(Edit4->Text);
double R5 = StrToFloat(Edit5->Text);
double R6 = StrToFloat(Edit6->Text);
double E1 = StrToFloat(Edit7->Text);
double E2 = StrToFloat(Edit8->Text);
double E3 = StrToFloat(Edit9->Text);

all those in a debug edit box. String to number functions are not always friendly, and you should validate that what you typed was indeed what the numbers became.
if this is not working, you can try atof, or try to understand what happened to it.

if this is working, tell us what you put in and and what you expected to get.

The problem is that you're computing the I1...I6 inside TForm1's constructor. That means they get computed once, when the form is constructed, and they never change after that.

You may be thinking that C++ programs work like spreadsheets, where you make a change in one cell and all dependent cells automatically update. C++ doesn't work that way. Statements are executed one at a time and once a statement is executed, it won't execute again unless you do something to make it execute.

So I'd move all that logic in TForm1::TForm1() to TForm1::Button1Click()
I've moved that logic as you said, but it still gives same results, no matter what I write in edits.
The code computes the values of I1..I6. Where does it actually display those values?
It display it in edits.
from the looks of it, you want to make your button click
- read the edits the user put in
- compute the value
- display to the target edit

all in that same function. If you do that, when the button is clicked, it will recompute and display the new answer.

its possible to use on-change events to trigger but that isnt useful here because you probably want to change multiple edit boxes before recomputing, not recompute every time they change one value (?).
I've moved that logic as you said, but it still gives same results, no matter what I write in edits.
Please show your current version of TForm1::Button1Click()
Topic archived. No new replies allowed.