Sunday 23 April 2017

Preventing Infinite Loops (Basic Syntax) in Crystal Report

There is a safety mechanism to prevent report processing from hanging due to an infinite loop. Any one evaluation of a formula can have at most 100,000 loop condition evaluations per formula evaluation. For example:
Dim i
i = 1
Do While i <= 200000
   If i > {movie.STARS} Then Exit Do
   i = i + 1
Loop
formula = 20
If {movie.STARS} is greater than 100,000 then the loop condition (i <= 200000) will be evaluated more than the maximum number of times and an error message is displayed. Otherwise the loop is OK.
Note   The safety mechanism applies on a per formula base, not for each individual loop. For example:
Dim i
i = 1
For i = 1 To 40000
   formula = Sin (i)
Next i
Do While i <= 70000
   i = i + 1
Loop
The above formula also triggers the safety mechanism since the 100,000 refers to the total number of loop condition evaluations in the formula and this formula will have 40001 + 70001 such evaluations.

No comments:

Post a Comment

Control Structures (Crystal Syntax) In Crystal Report : If Expressions (Crystal Syntax) in Crystal Report

Formulas without control structures execute each expression in the formula exactly once when the formula is evaluated. The expressions are...