Err:Reduce the Expression so it is less complex in for-loops

rthswrthsw Member Posts: 73
Hi there, there is clearly a error in nesting Loop-statements in Navision.

Try this (tested in Navision 4.0 SP3, build 27010):
for a := 1 to 2 do begin
  for b := 1 to 2 do begin
    for c := 1 to 2 do begin
      for d := 1 to 2 do begin
        for e := 1 to 2 do begin
          test := padstr('',5,'.');
          test := copystr('Test',1,2);
        end;
      end;
    end;
  end;
end;

Define a till e as integer or decimals (no difference), put the code in a Codeunit-run, in a tablefield, in a tablefunction, in a codeunit-Function... whereever you want. :lol:

Try to compile, you get the error mentioned in the headline. =D>
Both functions (test := ...) will lead to the error, much more (i.e. format(padstr) will also.
You can use this short Var-names, or even longer Var's, no difference. [-(

it seems, as the Compiler will turn into a stack-error. :bug:

If you comment the test :=... or remove one For-loop, everything will work fine, if you move 1-4 loops into an sub-codeunit, everything will work fine.

If you add another Loop, the error stays, if you delete the begin/end, where possible, the error stays. ](*,)

Did someone had this error before, and found a solution which will not need to call a sub-codeunit? :?:

Comments

  • kinekine Member Posts: 12,562
    I never needed more than 2 nested fors.... ;-) if you need this, the error is somewhere else for me... 8)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • DenSterDenSter Member Posts: 8,304
    Is this actually something you programmed for a customer? I would love to know what that is for. I agree with Kamil that if that is an error then fix your code that it compiles. The mere fact that you get a compilation error doesn't mean it's a bug. You might just have discovered a system limitation.
  • DaveTDaveT Member Posts: 1,039
    Hi,

    You not using a - e variables why not use one loop with 1 to 32 ?

    You could use a loop on the integer table if you need so may loops.
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • i4tosti4tost Member Posts: 208
    Move some loops (or code inside loops) into function (no need for other codeunit) and problem will be solved.
    I will agree with all comments. I have no idea why you need this? Can you give some example?
  • idiotidiot Member Posts: 651
    Replace all "for" with REPEAT..UNTIL & it will work.
    C/Side is a primitive language. "for" is probably considered too advanced for it to handle after a certain number of loops, my guess is the memory allocation is not optimized or the exe itself is never optimized even after it moved to 32 bit environments.
    NAV - Norton Anti Virus

    ERP Consultant (not just Navision) & Navision challenger
Sign In or Register to comment.