Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Loopin a variable length array
Message
From
20/02/1999 18:07:47
 
 
To
20/02/1999 17:06:40
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00189697
Message ID:
00189707
Views:
24
>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)
* add as many items as you want with AddElement(@cListToProcess, nRecalcItem)
DO WHILE LEN(cListTOProcess) > 0
   ReCalcElement(VAL(cListToProcess))  && and other parms, probably including
                                       && cListToProcess by reference if it 
                                       && might be extended during recalc
   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
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform