Help with REPEAT ... UNTIL !

jeromecorriveaujeromecorriveau Member Posts: 13
I did a loop and i would like to have the previous record of that loop (not the last record). How can i get the previous record ? My loop type is REPEAT...UNTIL. Is it possible to give me an example ?

Thanks in advance !

Sorry my english isn't very good!
Jerome

Comments

  • DenSterDenSter Member Posts: 8,307
    MyOtherRec.INIT // now it has blank and initial values
    If MyRec.FINDSET THEN REPEAT
      // do some code in here
      // do some more code in here
      MyOtherRec := MyRec; // so in the next iteratin of the loop you have the previous one
    UNTIL MyRec.NEXT = 0;
    
  • David_CoxDavid_Cox Member Posts: 509
    Do you want the previous as in DenSters answer or are you wanting to loop backwards?

    IF myRec.FIND('+')THEN // Find Last
    REPEAT
    {
    Do something
    }
    UNTIL MyRec.NEXT(-1) = 0; // Move to Previous Record


    The -1 is a step and you could use this to step through a record set
    This can be a positive to step forwards or a negative to step backwards.

    MyStep := -2; // Every Second Record
    IF myRec.FIND('+')THEN // Find Last
    REPEAT
    {
    Do something
    }
    UNTIL MyRec.NEXT(MyStep) = 0; // Move to Second Previous Record


    Next Button Code
    IF NEXT <> 0 THEN // Test for EOF
    NEXT; // Move to Next Record

    Previous Button Code
    IF NEXT(-1) <> 0 THEN // Test for BOF
    NEXT(-1); // Move to Previous Record

    :whistle:
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • DenSterDenSter Member Posts: 8,307
    David Cox wrote:
    Next Button Code
    IF NEXT <> 0 THEN // Test for EOF
    NEXT; // Move to Next Record

    Previous Button Code
    IF NEXT(-1) <> 0 THEN // Test for BOF
    NEXT(-1); // Move to Previous Record

    :whistle:
    Are you sure that doesn't do NEXT twice? IF NEXT(-1) is not 0, then it just performed the NEXT(-1) to make sure it can right? I think all you need for the code is:
    IF NEXT(1) = 0 THEN;
    or:
    IF NEXT(-1) = 0 THEN;
  • David_CoxDavid_Cox Member Posts: 509
    DenSter wrote:
    David Cox wrote:
    Next Button Code
    IF NEXT <> 0 THEN // Test for EOF
    NEXT; // Move to Next Record

    Previous Button Code
    IF NEXT(-1) <> 0 THEN // Test for BOF
    NEXT(-1); // Move to Previous Record

    :whistle:
    Are you sure that doesn't do NEXT twice? IF NEXT(-1) is not 0, then it just performed the NEXT(-1) to make sure it can right? I think all you need for the code is:
    IF NEXT(1) = 0 THEN;
    or:
    IF NEXT(-1) = 0 THEN;

    Yes you are right I was in the wrong language mindset, testing for BOF or EOF before moving the record pointer, I was away with the old VB code!
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • DenSterDenSter Member Posts: 8,307
    I thought so. You got me a bit confused becasue I have been working with ADO recordsets lately and have gotten used to EOF and BOF properties :) man it's easy to mix those up.
Sign In or Register to comment.