Welcome to the SRP Forum! Please refer to the SRP Forum FAQ post if you have any questions regarding how the forum works.
For Each suggestion
Referring to this example of code:
If Array happens to be null, the "For Each" loop will still process the code within the block one time with Field = "". Would it make more sense to skip the block of code if Array = "" in these cases? Just a thought...
For Each Field in Array
// Processing for each field
Next Field
If Array happens to be null, the "For Each" loop will still process the code within the block one time with Field = "". Would it make more sense to skip the block of code if Array = "" in these cases? Just a thought...
Comments
// Field is @vm delimited Cnt = Dcount(Field, @vm) For I = 1 to Cnt Value = Field<1, I> // Process through each value of the Field Next I // Using For Each syntax... For Each Value in Field using @vm setting I // Process through each Value of the Field Next Field
In the For, Next statement, if Field were to equal null, then processing would be ignored because Cnt would be set to the value of zero.
In the For Each statement, processing occurs even if Field were equal to null. I would expect it to skip the processing where the Field = "".
If Field were to equal a list of null values (i.e. Field = "":@vm:"":@vm:"") then both would cycle through each null value as expected.
If explicit rules were intended rather than implicit rules (which I always prefer to eliminate ambiguity in my code), then I would suggest that this is better logic:
If Field NE '' then // Using For Each syntax... For Each Value in Field using @vm setting I // Process through each Value of the Field Next Field end
The way it is currently, "" is treated as an array with one element that is empty. So, in order to treat "" as empty, we need to do the following:
If Field NE '' then For Each Value in Field using @vm setting I // Do stuff with Value Next Field end
Let's say we update the For...Each loop to treat "" as an empty list. Now, when I need to treat "" as a list with one element (because eventually someone will need it), I have to do this:
If Field EQ '' then // Do stuff with Value end else For Each Value in Field using @vm setting I // Do stuff with Value Next Field end
Which work around is preferred? The real issue is that "" has ambiguous meaning in BASIC+. There is no truly empty list unless you count unassigned variables.
For Each NonNull Value in Field setting I // Do stuff with Value Next Value