>>>>What is the limit of CASE in a DO CASE ?
>>>
>>>I don't think there is one.
>>>
>>>But for practical reasons, please consider the following example:
>>>
>>>
>>>do case
>>>case x = 1
>>> ...
>>>case x = 2
>>> ...
>>>case x = 3
>>> ...
>>>...
>>>case x = 500
>>> ...
>>>endcase
>>>
>>>
>>>If "x" happens to be equal to 500, Visual FoxPro must analize all 500 cases, before carrying out the desired action. If this happens often, i.e., in a tight loop, performance will be bad. It might be much more efficient to split it, for example, as follows:
>>>
>>>
>>>do case
>>>case x <= 100
>>> do case
>>> case x <= 10
>>> case x = 1
>>> ...
>>> case x = 2
>>> ...
>>> case x <= 20
>>> case x = 11
>>> ...
>>> case x = 12
>>> ...
>>>case x <= 200
>>>...
>>>
>>>
>>>Or something similar. Much less CASEs to be analyzed, for any given number.
>>
>>Good idea Hilmar. I was taught to place the CASE statements most likely to occur first. That is sometimes easy and worthwhile and at othertimes... :)
>
>Oh, right, that's another way to make the CASE more efficient.
>
>But usually, I never got to more than 5-10 CASEs or so, so I don't think this was a major issue for me.
>
>Another consideration: If you really need, say, 500 CASEs, it might be worth-while to analyze the problem, and see if there isn't a more generic approach, that can be fit into much less CASEs. IOW, if there really are (say) 500 CASEs, there may be a lot of duplicate code.
I think that if you have too many CASE statements it is time to analyze your application. Once I had to have about a dozen CASE statements and each one had additional CASE statements within it. That was in the FP 2.6 days. Business objects can make things easier to some extent.