Calculate numbers from MSFlexGrid

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

    #1

    Calculate numbers from MSFlexGrid

    I am developing a program of an information system for reservoir operation. I have a table, MSFlexGrid1 with 4 columns of Initial Depth, End Depth, Cut Volume, and Fill Volume (see attachment 'a.jpg'). There is a button 'Calculate' next to the table which whenever user clicks the button another form containing another MSFlexGrid table will appear. This table contains 2 columns which are Depth and Cumulative Volume (see attachment 'b.jpg'). Cumulative Volume is the sum of Cut Volume and/or Fill Volume at each Depth. So far i have this code from a helpful friend in Bytes, but somehow it sums only the Cut Volume (CUTVOL).
    Code:
          For ARRAYDATAidx = 2 To UBound(ARRAYDATA) '§ loop trough the ARRAYDATA and add each line in the MSFlexGrid1
             MSFlexGrid1.AddItem ARRAYDATA(ARRAYDATAidx).DEPTH1 & vbTab & _
                CStr(Format(CSng(ARRAYDATA(ARRAYDATAidx - 1).CUTVOL) + _
                CSng(.TextMatrix(ARRAYDATAidx - 1, 1)), "#.0"))
          Next
    how can i modify this code to make it calculate both CUTVOL and FILLVOL?
    Attached Files
  • Guido Geurs
    Recognized Expert Contributor
    • Oct 2009
    • 767

    #2
    Hey,
    If its Cutvol AND (or) fillvol then its:
    Code:
          For ARRAYDATAidx = 2 To UBound(ARRAYDATA) '§ loop trough the ARRAYDATA and add each line in the MSFlexGrid1
             If ARRAYDATA(ARRAYDATAidx - 1).CUTVOL <> "" Then
                MSFlexGrid1.AddItem ARRAYDATA(ARRAYDATAidx).DEPTH1 & vbTab & _
                   CStr(Format(CSng(ARRAYDATA(ARRAYDATAidx - 1).CUTVOL) + _
                   CSng(.TextMatrix(ARRAYDATAidx - 1, 1)), "#.0"))
             Else
                MSFlexGrid1.AddItem ARRAYDATA(ARRAYDATAidx).DEPTH1 & vbTab & _
                   CStr(Format(CSng(ARRAYDATA(ARRAYDATAidx - 1).FILLVOL) + _
                   CSng(.TextMatrix(ARRAYDATAidx - 1, 1)), "#.0"))
             End If
          Next
    Attached Files

    Comment

    • Mas Juliza Alias
      New Member
      • Aug 2010
      • 67

      #3
      THANKS! that works nicely. I've learnt a lot from your code. Thank YOU! :)

      Comment

      Working...