Just wondering how i would create a function to sum a column in a MSFlexGrid? I wanted to have a coomadnbutton to perform the function and a textbox to display it. Is this possible and can anyone help?
Thanks for the help but it doesn't seem to be working....it gives me the error "Compile Error: ByRef argument type mismatch" ....what does that mean?"
Private Sub Command22_Click()
Text1.Text = TotalColumn(FlexGrid, 15) ' 15 is my column i would like to sum
End Sub
Private Function TotalColumn(Grid As MSFlexGrid, ByVal ColIndex As
Integer) As Integer
Dim R As Long
Dim Total As Integer
For R = 0 To Grid.Rows - 1
If IsNumeric(Grid.TextMatrix(R, ColIndex)) Then
Total = Total + Grid.TextMatrix(R, ColIndex)
End If
Next R
The only thing I can see right away is in your function header:
Private Function TotalColumn(Grid As MSFlexGrid, etc...)
'Change to:
Private Function TotalColumn(Grid AS MSHFlexGrid, etc...)
Also, when you call the function, i.e. "Text1.Text = TotalColumn(FlexGrid, 15)", make sure that 'FlexGrid' is the name of your grid.
At any rate, a ByRef argument type mismatch error is blaming the grid part of the function call, but the rest looks ok...try checking these and see what happens.
~Mike
Any man willing to sacrifice liberty for security deserves neither liberty nor security.
Try changing this line:
If IsNumeric(Grid.TextMatrix(R, ColIndex)) Then
Total = Total + Grid.TextMatrix(R, ColIndex)
to this:
If IsNumeric(CInt(Grid.TextMatrix(R, ColIndex))) Then
Total = Total + CInt(Grid.TextMatrix(R, ColIndex))
You may have spaces or something else that's causing IsNumeric() to return false. Put a breakpoint on the line that increments Total and make sure it's actually getting there, it sounds like it's not...
Any man willing to sacrifice liberty for security deserves neither liberty nor security.
it was actually my TotalColumn = Total....i misspelled "column"....working good....but now i'm sometimes getting "Overflow" error...looks like the number might be too large...any suggestions?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.