Counting filtered records for progress bar.

JamieBrownJamieBrown Member Posts: 107
Hi,

I'm (quite clearly) a newbie and am having a problem counting the number of filtered records (for a progress bar)

At the moment I'm obviously using, variable := Count();

But this is counting all records in the table as oppopsed to just the filtered ones, regardless of where I call the function. Am I missing something obvious here or is another function needed?

As always, your help is much appreciated.

Jamie

Comments

  • Timo_LässerTimo_Lässer Member Posts: 481
    I always use something like the following code for a progress bar window:
    MyRec.SETCURRENTKEY([...]);
    MyRec.SETRANGE([...]);
    Window.OPEN('Processing Data... @1@@@@@@@@@@@@@');
    NoOfRecs := MyRec.COUNT;
    CurrRec := 0;
    
    IF MyRec.FIND('-') THEN 
      REPEAT
        CurrRec += 1;
        Window.UPDATE(1,ROUND(CurrRec / NoOfRecs * 10000,1));
    
        [...]
      UNTIL MyRec.NEXT = 0;
    Window.CLOSE;
    
    Timo Lässer
    Microsoft Dynamics NAV Developer since 1997
    MSDynamics.de - German Microsoft Dynamics Community - member of [clip]
  • JamieBrownJamieBrown Member Posts: 107
    Hi, Still can't get it to work. I'm bascially only displaying items that have 2 or more valid prices. Below is the code used:

    What would totalrec need to be set to?

    thanks



    Item - OnPreDataItem()
    LastFieldNo := FIELDNO("No.");

    window.OPEN('Item : #1##########\' +
    'No. of Prices : #2##########\' +
    'Progress : @');


    Item - OnAfterGetRecord()
    IF price.GET(Item."No.") THEN;
    price.SETFILTER(price."Item No.",Item."No.");

    Numofprices := price.count;

    Totalrec := item.Count;

    IF numofprices < 2 THEN
    CurrReport.SKIP;

    currentrec += 1;
    window.UPDATE(1,Item."No.");
    window.UPDATE(2,numofprices);
    window.UPDATE(3,ROUND(currentrec / totalrec * 10000,1));
  • krikikriki Member, Moderator Posts: 9,118
    Some changes :
    globals for the progressbar

    diaProgress Dialog
    intProgress Integer
    intProgressI Integer
    intProgressTotal Integer
    timProgress Time


    Item - OnPreDataItem()
    LastFieldNo := FIELDNO("No.");
    
    
    diaProgress.OPEN('@1@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\',intProgress);
    intProgressTotal := COUNT; // be carefull : this can be slow if filters don't use the key
    // SQL : use COUNTAPPROX, faster but this doesn't always give an exact number
    timProgress := TIME;
    


    Item - OnAfterGetRecord()
    // Progress bar
    intProgressI := intProgressI + 1;
    IF timProgress < TIME - 3000 THEN BEGIN // every 3 seconds
      // Not on every loop, because updating a dialogbox costs a lot of time
      timProgress := TIME;
      intProgress := ROUND(intProgressI / intProgressTotal * 10000,1);
      diaProgress.UPDATE;
    END;
    
    IF price.GET(Item."No.") THEN;
    price.SETFILTER(price."Item No.",Item."No.");
    
    Numofprices := price.count;
    
    Totalrec := item.Count;
    
    IF numofprices < 2 THEN
     CurrReport.SKIP;
    

    Item - OnPostDataItem
    diaProgress.CLOSE;
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • JamieBrownJamieBrown Member Posts: 107
    Kriki,

    Perfect!

    Thanks alot.

    Jamie
Sign In or Register to comment.