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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to move values in array?

Status
Not open for further replies.

puk5629

Programmer
Jul 11, 2010
13
GB
Hi everyone,

I'm create an array with values in it and those values will be recalculate and put into another array. I used a 'if' function to eliminate some valuse.

The problem that i face is i don't know how to put those newly created values accordingly in the second array.

For example, after i run the programme, the outcome that i got is

i j Array2 But I wan it to be arranged become,
0 0 0 Array2[0,0]=5
0 1 0 Array2[0,1]=3
1 0 5 Array2[1,0]=2
1 1 3 Array2[1,1]=4 only.
2 0 0
2 1 0 How can I do so?
3 0 0
3 1 0
4 0 2
4 1 4
5 0 0
5 1 0

This is the sample programme that i wrote,

for i:=0 to 6-1 do
begin
begin
if Array1[i,0]>0 then
A:=Array1[i,0]+5;
B:=Array1[i,1]-5;
end

begin
Array2[i,j]:=A;
Inc(j);
Array2[i,j]:=B;
j:=0;
A:=0;
B:=0;
end;
end;
 
I am not entirly sure what you are trying to achieve, but
I can see a few problems stright away.

You are not initalising 'j' it probobly will be zero but never assume that.

Code:
 if Array1[i,0]>0 then  
 A:=Array1[i,0]+5;  
 B:=Array1[i,1]-5;

You dont have any brackets (begin /end) here so the second statement (B:=Array1[i,1]-5) will always execute, regardless of the test result (this might be what you want it to do ?)

You have brackets where you dont need brackets.

Your array1 has 13*2 elements but you are only doing 5 loops.

If the test is false then the value of 'A' is undefined but will be stored in the array.
Also you wont get the results that you have you shown, did you cut and paste your code?



Steve: N.M.N.F.
If something is popular, it must be wrong: Mark Twain
 
The coding is just an example of what I'm trying to do. Not every values in Array1 is larger than 0. So for those that are larger than 0, it would calculate A and B and insert them in Array2. For those values in Array1 that are smaller than 0, it would save as 0 in Array2.

Actually i'm trying to check the position which content X,Y and Z values within an area and save them in another new array and the result that i get from my coding is similar to what i have post here.

I'm trying to delete the rows that have values of 0, so that Arrray2 only content rows that with values in it. That's basically what i trying to achieve.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top