Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help: I need a way to add subtotals to a merged grid!

Status
Not open for further replies.

patrickdrd

Programmer
Nov 21, 2003
149
0
0
GR
Hi guys! I have a merged flexgrid and I need to find a way to add subtotals to it (A sum of all the merged lines). Does anyone have any ideas?

Thanks in advance!
 
Use an incode counter/variable declared as double. After your grid's filled up you have the the sum of your values.
If you have more value's to summarize, use an array.


[ponder]KrK
 
patrickdrd,

Try my sample code:

Private Sub Command1_Click()
With MSHFlexGrid1
.TextMatrix(1, 1) = 2
.TextMatrix(1, 2) = 3
.TextMatrix(1, 3) = 2
.TextMatrix(1, 4) = 2

.TextMatrix(2, 2) = 5
.TextMatrix(2, 3) = 5
.TextMatrix(2, 4) = 7
.TextMatrix(2, 5) = 5
.TextMatrix(2, 6) = 5
.TextMatrix(2, 7) = 5

.TextMatrix(3, 1) = 6
.TextMatrix(3, 3) = 6
.TextMatrix(3, 4) = 6
.TextMatrix(3, 5) = 6
.TextMatrix(3, 6) = 5
.TextMatrix(3, 7) = 5

.MergeCells = flexMergeFree
.MergeRow(1) = True
.MergeRow(2) = True
.MergeRow(3) = True
End With
End Sub

Private Sub Command2_Click()
Dim icol As Integer
Dim irow As Integer
Dim iSubTotal As Integer
Dim blnEven As Boolean


With MSHFlexGrid1
For irow = 1 To .Rows - 1
blnEven = True
For icol = 1 To .Cols - 2

If .MergeRow(irow) = True Then
If Val(.TextMatrix(irow, icol)) = Val(.TextMatrix(irow, icol + 1)) Then
If blnEven Then
iSubTotal = iSubTotal + Val(.TextMatrix(irow, icol)) + _
Val(.TextMatrix(irow, icol + 1))
Else
iSubTotal = iSubTotal + Val(.TextMatrix(irow, icol))
End If
blnEven = Not blnEven
End If
End If

Next icol
Next irow
End With

MsgBox iSubTotal
End Sub

Private Sub Form_Load()
MSHFlexGrid1.MergeCells = flexMergeFree
End Sub

Vladk
 
patrickdrd,

I am not sure what you exactly need: that code calculates sum of all sells that are immediate neighbors in the merged rows when they have the same values.

It does not calculate sum of the displayed merged values. But it should give the idea.

VladK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top