Wilder1626
asked on
Biggest number in column 2 of a MSFlexgrid
Hello all,
I would like, by a click on a button, look at the biggest number entered in the second column of MSFLexgrid1, and then, put that number in my Label1.
The numbers are not in sequence.
How can i do this please?
Thanks for your help.
I would like, by a click on a button, look at the biggest number entered in the second column of MSFLexgrid1, and then, put that number in my Label1.
The numbers are not in sequence.
How can i do this please?
Thanks for your help.
With formatting...
Private Sub cmd1_Click()
lbl1.Caption = findLargestItemInFlexGridColumn(fg, 1)
End Sub
Private Function findLargestItemInFlexGridColumn(fg As MSFlexGrid, fgCol As Integer) As Double
Dim i As Integer
Dim maxValue As Double
maxValue = fg.TextMatrix(0, fgCol)
For i = 0 To fg.Rows - 1
If CDbl(fg.TextMatrix(i, fgCol)) > maxValue Then maxValue = CDbl(fg.TextMatrix(i, fg.Col))
Next i
findLargestItemInFlexGridColumn = maxValue
End Function
ASKER
Hello,
I have a type incompatible with that part of the code:
maxValue = fg.TextMatrix(0, fgCol)
Do you know why?
Thanks again for your help.
I have a type incompatible with that part of the code:
maxValue = fg.TextMatrix(0, fgCol)
Do you know why?
Thanks again for your help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Perhaps the column number should be 1, not 2, sorry.
The columns are numbered from zero to "cols-1", so the second column would be "column 1"
Therefor the "Click" sub should read:
Private Sub cmdCommand1_Click()
lblLabel1.Caption = findLargestItemInFlexGridC olumn(MSFl exGrid1, 1)
End Sub
I think you would find this faster than performing a "For Next" loop which invloves calculation at each looping. Array sorts are much faster.
The columns are numbered from zero to "cols-1", so the second column would be "column 1"
Therefor the "Click" sub should read:
Private Sub cmdCommand1_Click()
lblLabel1.Caption = findLargestItemInFlexGridC
End Sub
I think you would find this faster than performing a "For Next" loop which invloves calculation at each looping. Array sorts are much faster.
ASKER
Oh yessss,
Thanks, it work.
Thanks, it work.
Private Sub cmd1_Click()
lbl1.Caption = findLargestItemInFlexGridC
End Sub
Private Function findLargestItemInFlexGridC
Dim i As Integer
Dim maxValue As Double
maxValue = fg.TextMatrix(0, fgCol)
For i = 0 To fg.Rows - 1
If CDbl(fg.TextMatrix(i, fgCol)) > maxValue Then maxValue = CDbl(fg.TextMatrix(i, fg.Col))
Next i
findLargestItemInFlexGridC
End Function