How to get average values from a flexgrid and dump them into another flexgrid?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mas Juliza Alias
    New Member
    • Aug 2010
    • 67

    How to get average values from a flexgrid and dump them into another flexgrid?

    Hi,

    I have two tables (MSFlexGrid1 & MSFlexGrid2). MSFlexGrid2 contains data of Date, Time, Water Level, Volume, and Area. Some of the Date are the same in which the data are taken at different times of the same date. What I need here is that the average of the Water level, Volume, and Area data of the same date to be filled in the other table, MSFlexGrid1. The table should contain data of Date and the average of Water level, Volume, and Area of the same date from MSFlexGrid2. I already get the unique value of the date to be filled in MSFlexGrid1, with help from a helpful friend in Bytes, but I do not manage to get the average of those values sharing the same date.

    Attached is the program i have so far. There are two command buttons on the first form, Sort and Next. Click Sort button to sort the data according to the date, and Next button to go to the next form, Form2. After select the From Date and To Date, the selected data should appear in both grids, MSFlexGrid2 and MSFlexGrid1.

    Thank you in advance.
    Attached Files
  • Guido Geurs
    Recognized Expert Contributor
    • Oct 2009
    • 767

    #2
    Sorry for this late response but I'm working on it.

    I have seen that the data is sorted!
    So, I think the code can be as follow:
    - Go in the recset to the first date of "DateFrom", loop until the date changes.
    - concatenate all the values for volume, ... with the same date and count the times there is data for the same date.
    - when the date changes, add to the average grid the (concatenated values/count).
    - Loop this until the date is > "DateTo".

    Maybe I have a working code today.

    Comment

    • Guido Geurs
      Recognized Expert Contributor
      • Oct 2009
      • 767

      #3
      I hope this is the code you are looking for.
      Attached Files

      Comment

      • Mas Juliza Alias
        New Member
        • Aug 2010
        • 67

        #4
        Yes, it is. The code working so well. I've tried to solve this quite a while but turns out not like I want it to be. I'm in the process to understand your code. Did you use the Breakpoint and Watch as in your article each time you solve a problem? I'm just amazed how you can solve a problem in such a short time.
        Thank YOU & Happy Teacher's Day (I think of you as my VB teacher) :)

        Comment

        • Guido Geurs
          Recognized Expert Contributor
          • Oct 2009
          • 767

          #5
          I almost always use Breakpoint and watch.
          If I want to know the structure or contents of an array, which property a value of a component is keeping, the evolution of variables in a ForNext,... (see attached GIFs)
          Attached Files

          Comment

          Working...