Please help newbeeeeee...

Said
Said Member Posts: 20
Hi,

How do I loop through all records in a table from first to last?
I'm using this code but it only gives me the first record in the table:

Count :=0;
IF Customer.FIND('-') THEN
MESSAGE('Customer %1 is %2','Name',Customer.Name);
Count:=Count+1;
REPEAT
UNTIL Customer.NEXT <= 0;

Thank you

Comments

  • OliverT
    OliverT Member Posts: 37
    edited 2004-08-18
    hi!

    you should wirte the code you want to repeat in the repeat ... not before or after it ;)

    this should work
    Count := 0;
    IF Customer.FIND('-') THEN
      REPEAT
        MESSAGE('Customer %1 is %2','Name',Customer.Name);
        Count:=Count+1;
      UNTIL Customer.NEXT = 0;
    
  • pduck
    pduck Member Posts: 147
    Count := 0;
    IF Customer.FIND('-') THEN
      REPEAT
        MESSAGE('Customer %1 is %2','Name',Customer.Name);
        Count:=Count+1;  
      UNTIL  Customer.NEXT=0;
    

    you don't need a count, cause you can get it so: Customer.COUNT

    something different ... do you have any programing experience ? it doesn't seem so learning programing AND navision is very very hard. maybe you should take a course first ?
  • PEzechiels
    PEzechiels Member Posts: 83
    The Count or any syntax should be between the repeat and the until otherwise you will only get the first record in the table.
    If your purpose is to count all the records in the customer table than "Customer.Count" should be enough.
    Also if you wish to modify or delete some records you should really think about using setfilter or setrange before the find syntax.
    That way the processing goes faster.
  • Said
    Said Member Posts: 20
    Thanks a lot for your help
  • DenSter
    DenSter Member Posts: 8,307
    Don't put the count within the repeat. If you have 10,000 customers in your record set, you will count 10,000 times. Better to put in an extra line before the REPEAT, like this:
    Count := 0;
    IF Customer.FIND('-') THEN BEGIN
      Count := Customer.COUNT;
      REPEAT
        MESSAGE('Customer %1 is %2','Name',Customer.Name);
      UNTIL  Customer.NEXT=0;
    END;
    
  • Sorcerer
    Sorcerer Member Posts: 107
    ...and for SQL use COUNTAPPROX...
  • DenSter
    DenSter Member Posts: 8,307
    Use COUNTAPPROX if you don't want an exact number. If you want to know exactly how many records are in your filter, then do NOT use COUNTAPPROX, but use COUNT. The other one is meant to get a quick estimate of the number of records in your filter, and supposedly is easier on network bandwidth. But let's face it, if I want to know how many records, I have a good reason to want to know it, and I want an exact count. I never use COUNTAPPROX.
  • Sorcerer
    Sorcerer Member Posts: 107
    May be...but as Microsoft says you have to use COUNTAPPROX if you use SQL...