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

Elements Position in an array - revisited 1

Status
Not open for further replies.

chuckyfiche

IS-IT--Management
May 20, 2004
5
CA
I would like to revisit a post from earlier in the year I just came across;

I've attempted to reproduce the formula to calculate the value of an array, based on it's position.

I'm failing on the exit statement, where Crystal is indicating it's waiting for a 'while' statement. I'm using Crystal 8.5.

I've kept the formula close to the original and followed the logic but still cannot get it to work. I would appreciate any suggestions the forum might have.

Michael

>>>>>>>>>>>>>>

if not({TABLE.PART} in PART_Array )then
(
sCounter := sCounter +1;
Redim Preserve PART_Array[sCounter];
Redim Preserve QTY_Array[sCounter];
PART_Array[sCounter] := {TABLE.PART};
NewQty := {@Available};
QTY_Array[sCounter] := NewQty;
)
else

(
max := ubound(PART_Array);
BooleanVar Flag := False;
While sCounter < max and Flag = false do
(
sCounter:=sCounter+1;
if{TABLE.PART} = PART_Array[sCounter] then
(
NewQty := QTY_Array[sCounter]-{TABLE.ORDER_QTY};
QTY_Array[sCounter] := NewQty;
Flag := True;
);
if Flag then exit do;
);
);

NewQty;

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

 
Your handling of the looping is fine....though I prefer using a FOR loop for this

Your problem I think is that the 2 halves of your IF statement don't end in the same variable type. The first half ends with

QTY_Array[sCounter] := NewQty;

and the second ends with

Flag := True;

A number and a boolean don't mix

SO...the simplest way to end it is to end the first with a Boolean as well. NOTE: I moved the declaration of Flag to the front

Also this is redundant and may cause a problem

if Flag then exit do;
and
While sCounter < max and Flag = false do

the while statement will kick out of the loop no problem...and I don't think there is an "exit do" in Crystal

Also it should be sCounter <= max //you will never test the max value otherwise.

so try this version

BooleanVar Flag := False;

if not({TABLE.PART} in PART_Array )then
(
sCounter := sCounter +1;
Redim Preserve PART_Array[sCounter];
Redim Preserve QTY_Array[sCounter];
PART_Array[sCounter] := {TABLE.PART};
NewQty := {@Available};
QTY_Array[sCounter] := NewQty;
Flag := False;
)
else

(
max := ubound(PART_Array);
While sCounter <= max and Flag = false do
(
sCounter:=sCounter+1;
if{TABLE.PART} = PART_Array[sCounter] then
(
NewQty := QTY_Array[sCounter]-{TABLE.ORDER_QTY};
QTY_Array[sCounter] := NewQty;
Flag := True;
);
);
);

NewQty;



Jim Broadbent

The quality of the answer is directly proportional to the quality of the problem statement!
 
Thank you both. The Boolean variable AND the exit statement were both causing problems.

I didn't look at the top-half of the IF statement, because it worked. Turns out the blinders were preventing me from seeing the [obvious] problem with the different results from both halves of the formula.

As soon as I removed the exit statement, I got an error stating the value should be a number . . . because of the flag := true not matching the top-half of the if statement.

I sort of thought, based on what I've read, it's a good idea to build-in a second method of booting out of the if statement - thus the exit do (which should have been while)

Thank you again.

Michael
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top