Looping through MsFlexGrid rows

2.3k views Asked by At

I have a question about MsFlexGrid VB6. I have a grid containing coordinates of objects vertices. So for example, if I have 4 objects each one with 3 vertices, the number of rows is 4*3=12. What I would like to do is:

Loop through every three rows (the number of vertices) and get the maximum value and then have it appear in a MsgBox and then move to the next three vertices and do the same.

Is this possible?

1

There are 1 answers

0
41686d6564 On

Assuming your values are in the first column, you can do something like this:

Dim maxValue As Double
For i = 0 To MSFlexGrid1.Rows - 1
    Dim value As Double
    value = Val(MSFlexGrid1.TextMatrix(i, 0))
    If value > maxValue Then maxValue = value

    If (i + 1) Mod 3 = 0 Then
        MsgBox CStr(maxValue)
        maxValue = 0
    End If
Next i

If your MsFlexGrid has row/column headers (fixed rows/columns) that you'd like to skip, you would need to adjust the above code. For example, make the loop start with 1 instead of 0 if you have one fixed row. And use MSFlexGrid1.TextMatrix(i, 1) if you have one fixed column before the actual data.