Thought I'd pass along this gotcha I just encountered when looping through some actions where you're parsing arrays and randomly selecting an item from the array. But you only execute some of the functionality depending on the results of a previous call.
For instance my scenario is this:
Go to a page that initially displays one dropdown.
Capture the values into an array and randomly select one of those values.
That selection creates a post to the server, and depending on the value may or MAY NOT display a second and third drop-downs to choose from.
So what I do is use the array count to determine if I need to randomly select something from the second and third drop downs.
I loop through the section of my script a random number of times which adds lines to an overall report.
My gotcha was that I was not resetting the array counters to zero at the end of each loop, so for subsequent loops, sometimes, the array counters were greater than zero even though I had not executed the code to populate the array.
My final post after the array would error because sometimes I would be populating fields 1 and 3 when only field 1 should have been populated.
Don't know if I'm explaining this well, but bottom line is it's a good habit to get into to ZERO your array counters after you're done with them such as:
<font class="small">Code:</font><hr /><pre>
For i := 1 to whatever do
WebParseDataBoundArray(yaddayadda, nArrayCounter1);
WebURLPost(something);
if nArrayCounter1 &gt; 0 then
WebParseDataBoundArray(yaddayadda, nArrayCounter2);
WebURLPost(something);
if nArrayCounter2 &gt; 0 then
WebParseDataBoundArray(yaddayadda, nArrayCounter3);
WebURLPost(something);
end;
end;
WebFormPost(This contains the results for the above actions);
nArrayCounter1 := 0;
nArrayCounter2 := 0;
nArrayCounter3 := 0;
End; //of for loop
</pre><hr />
FYI, this is not a very good example because my logic and subsequent actions are actually seperated out into function calls. But bottom line I wanted to pass along is to make sure to zero/clear values you're using over within loops.
[img]/images/graemlins/wink.gif[/img]