SRL Archive - Help

Array Help,


Mat

2012-07-09 15:57:26

I have a Array, full on Extended's.
I want to Take each one * by a number and add it to another array in the exact same position, I'm currently stumped atmo.
Thanks
Mat

x[Warrior]x3500

2012-07-09 16:09:24


program new;
var
arrayOne, arrayTwo: array of Extended;
i: integer;

begin
arrayOne:= [1,2,3,4,5,6,7];
arrayTwo:= [7,6,5,4,3,2,1];

for i:=0 to high(arrayOne)do
begin
arrayOne[i]:= arrayOne[i]*{insert num here};
end;

for i:=0 to high(arrayOne)do
begin
arrayTwo[i]:= arrayOne[i]+arrayTwo[i];
end;
end.

Nebula

2012-07-09 16:11:43

Try Something like this… not sure if it will work though.


Procedure mat;
var
StartArray, EndArray: TVariantArray;
begin
SetLength(EndArray, StartArray);
For i := 0 to high(StartArray) do
EndArray[i] := (StartArray[i] * ###);
end;

Runaway

2012-07-09 16:34:50

From: Nebula
Try Something like this… not sure if it will work though.


Procedure mat;
var
StartArray, EndArray: TVariantArray;
begin
SetLength(EndArray, StartArray);
For i := 0 to high(StartArray) do
EndArray[i] := (StartArray[i] * ###);
end;


It will work if you do this:


Procedure mat;
var
StartArray, EndArray: TVariantArray;
i: Integer; // <- dat guy
begin
SetLength(EndArray, Length(StartArray)); // <- length too :P
For i := 0 to high(StartArray) do
EndArray[i] := (StartArray[i] * ###);
end;

Not entirely sure what you're trying to do, but replacing it's own values works just fine :o


Procedure MultiplyArray(Num: Extended);
var
Arr: TExtendedArray;
i: Integer;
begin
For i := 0 to High(Arr) do
Arr[i] := Arr[i] * Num;
end;

Get a little fancy, maybe?


Procedure MultiplyArray(Num: TExtendedArray);
var
Arr: TExtendedArray;
i: Integer;
begin
For i := 0 to High(Arr) do
Arr[i] := Arr[i] * Num[i];
end;

How about a few specific values?


Procedure MultiplyArray(Num: Extended; Which: TExtendedArray);
var
Arr: TExtendedArray;
i, ii: Integer;
begin
For i := 0 to High(Arr) do
begin
For ii := 0 to High(Which) do
begin
if (Arr[i] = Which[ii]) then
Arr[i] := Arr[i] * Num;
end;
end;
end;

/bored

Mat

2012-07-15 07:45:16

Lol, Thanks for neg rep I totally forgot about this I was to busy in code.

Justin

2012-07-15 07:46:22

Wow, someone neg repped you for that? What has Villavu come to??