>Howdy,
>
>I have an array used to store references to controls on a multi-page form whose values may need to be recalculated.
>
>The form contains controls whose values may be dependent on the value of another control. The controls are linked though a form mediator. A control whose value is dependent on the value of another control sends a message during its Init() requesting notification when the first control's value changes.
>
>If the first control's value then changes, a reference to the requesting control is added to an array of controls to be recalculated.
>
>When it comes time to recalculate all of the dependent control values, the mediator loops through the recalculation array, calculating each control in turn.
>
>Here's the rub. As the mediator is processing the controls in the array, more than likely at least one of the controls processed has a dependency so that as that control's value is calculated, the dependent control adds itself to the end of the array so that it will then be recalculated in its turn.
>
>This means that the number of elements in the array is changing as the array is being processed.
>
>I have tried all combinations of FOR/ENFOR and FOR EACH/ENDFOR I can thing of, but have gone back to the tried and true DO/ENDDO loop to ensure that the entire array is processed.
>
>I am looking for a faster solution.
An approach that might work for you would be to use a string as a singly linked list; when the string is empty, you've finished. Your code might look something like:
cListToProcess = ""
#DEFINE cSepChar '~'
cListToProcess = STR(nFirstElementToRecalc)
DO WHILE LEN(cListTOProcess) > 0
ReCalcElement(VAL(cListToProcess))
nSepAt = AT(cSepChar, cListToProcess)
IF nSepAt = 0
cListTOProcess = ''
ELSE
cListToProcess = SUBST(cListToProcess, nSepAt + 1)
ENDIF
ENDDO
FUNCTION AddElement
LPARAMETERS cList, nThingToAdd
cList = cList + cSepChar + STR(nThingToAdd)
RETURN