Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get values from if function? 1

Status
Not open for further replies.

puk5629

Programmer
Jul 11, 2010
13
GB
Hi,

I'm trying to calculate some value under if function, but turns out 0 for the value that I wanted to obtain from it.

Here's my coding. The Nindex and Objectthickness are array of double. When i track the n1,n2,thickness,Nnumber and Tnumber, they all shows 0.

for k := 0 to m - 1 do
begin
n1:=0;
n2:=0;
thickness:=0;
Nnumber:=0;
Tnumber:=0;
if (Newrayposition[k,2]=Zobject1) then
begin
n1:=Nindex[0];
n2:=Nindex[1];
thickness:=Objectthickness[1];
Tnumber:=1;
Nnumber:=0;
end;
if (Newrayposition[k,2]=Zobject1+Objectthickness[1]) then
begin
n1:=Nindex[1];
n2:=Nindex[2];
thickness:=Objectthickness[2];
Tnumber:=2;
Nnumber:=1;
end;
if (Newrayposition[k,2]=Zobject1+Objectthickness[1]+Objectthickness[2]) then
begin
n1:=Nindex[2];
n2:=Nindex[3];
thickness:=Objectthickness[3];
Tnumber:=3;
Nnumber:=2;
end;
if (Newrayposition[k,2]=Zobject1+Objectthickness[1]+Objectthickness[2]+Objectthickness[3]) then
begin
n1:=Nindex[3];
n2:=Nindex[4];
thickness:=Objectthickness[4];
Tnumber:=4;
Nnumber:=3;
end;
if (Newrayposition[k,2]=Zobject1+Objectthickness[1]+Objectthickness[2]+Objectthickness[3]+Objectthickness[4]) then
begin
n1:=Nindex[4];
n2:=Nindex[5];
thickness:=Objectthickness[5];
Tnumber:=5;
Nnumber:=4;
end;
if (Newrayposition[k,2]=Zobject1+Objectthickness[1]+Objectthickness[2]+Objectthickness[3]+Objectthickness[4]+Objectthickness[5]) then
begin
n1:=Nindex[5];
n2:=Nindex[6];
thickness:=Objectthickness[6];
Tnumber:=6;
Nnumber:=5;
end;
if (Newrayposition[k,2]=Zobject1+Objectthickness[1]+Objectthickness[2]+Objectthickness[3]+Objectthickness[4]+Objectthickness[5]+Objectthickness[6]) then
begin
n1:=Nindex[6];
n2:=Nindex[7];
thickness:=Objectthickness[7];
Tnumber:=7;
Nnumber:=6;
end;
if (Newrayposition[k,2]=Zobject1+Objectthickness[1]+Objectthickness[2]+Objectthickness[3]+Objectthickness[4]+Objectthickness[5]+Objectthickness[6]+Objectthickness[7]) then
begin
n1:=Nindex[7];
n2:=Nindex[8];
thickness:=Objectthickness[8];
Tnumber:=8;
Nnumber:=7;
end;
ShowMessage('n1= '+FloatToStr(n1)+ ' n2= '+FloatToStr(n2));
ShowMessage('thickness = '+FloatToStr(thickness));
ShowMessage('Tnumber= '+FloatToStr(Tnumber)+ ' Nnumber= '+FloatToStr(Nnumber));
Caldelta2:=(n1/n2)*(sin(delta1));
delta2:=ArcSin(Caldelta2);
ShowMessage('delta2 = '+FloatToStr(delta2));
Bobject2:=thickness*Tan(delta2);
 
Your post does not include how you defined Nindex and Objectthickness. "array of double" implies Dynamic arrays, rather than Static. You also did not show how you initialized the arrays, nor how you have populated them.

Have you viewed them with a "Watch" or "Inspector" Window to see that they actually contain the proper values when program execution reaches this For Loop in your code?

Roo
Delphi Rules!
 
Thanks for the suggestion. I just found out that I redeclared a variable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top