Setrange Prob.

upasanisandipupasanisandip Member Posts: 405
edited 2006-04-07 in Navision Attain
Hi ,

Can anyone know how to solve this problem.

I want the min. serial no. value in table.

so using following code but getting 10 as return value.

Actual serial no. value in table is 20.

Vehicle is a record variable of subtype Vechicle Table.


Vehicle.SETRANGE(Vehicle."Serial No.",10,300);
MESSAGE('%1',Vehicle.GETRANGEMIN("Serial No."));



Thanks in adv.



Sandip.

Comments

  • krikikriki Member, Moderator Posts: 9,112
    GETRANGEMIN gets you the minimum value of the filter you created, not the minimum value in the DB.
    To get the min value, you need to create a loop to check it.
    Vehicle.SETRANGE("Serial No.",10,300); 
    IF Vehicle.FIND('-') THEN BEGIN
      MinSerialNo := Vehicle."Serial No.";
      REPEAT
         IF MinSerialNo > Vehicle."Serial No." THEN
          MinSerialNo := Vehicle."Serial No.";
      UNTIL Vehicle.NEXT = 0;
    END;
    
    MESSAGE('%1',MinSerialNo);
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • aniruddha_majumdaraniruddha_majumdar Member Posts: 57
    Hi
    Dear friend it will always give 10.
    Better take on key which is sorting on Serial NO.
    Do Setcurrent key
    then setrange
    and then find(-);
    u will get the result

    Soln given by kriki will also work
    Thanks & Regards,
    Aniruddha
  • krikikriki Member, Moderator Posts: 9,112
    Hi
    Dear friend it will always give 10.
    Better take on key which is sorting on Serial NO.
    Do Setcurrent key
    then setrange
    and then find(-);
    u will get the result

    Soln given by kriki will also work
    My solution is faster for writing in the table, because no extra key has to be maintained, but slower in reading, because it has to read some records.

    The extra-key solution of aniruddha_majumdar is faster for reading, because with 1 read it has the correct record, but it will be slower to write in the table.

    So if the code to read it has NOT to be lightening-fast for some reasons, it is best to use my solution.
    If your code has to be lightening-fast (e.g. it is part of a posting-procedure), then it is best to use the extra-key-solution.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • upasanisandipupasanisandip Member Posts: 405
    ok thanks . I exactly want the same.
Sign In or Register to comment.