vb6error-handlingmsflexgrid

How to solve MSFlexGrid Error 30006 in VB6


MSFlexGrid gives this 30006 Error each time it reaches ~350,000 cells.

Error Definition:

Run-time error '30006':

Unable to Allocate Memory For FlexGrid

My Code Sample:

Do While Not rs.EOF
    With MSFlexGrid1
        .Rows = .Rows + 1
        .TextMatrix(i, 1) = rs.Fields("1")    's1
        .TextMatrix(i, 2) = rs.Fields("2")    's2
        .TextMatrix(i, 3) = rs.Fields("3")    'f1
        .TextMatrix(i, 4) = rs.Fields("4")    'gr1
        .TextMatrix(i, 5) = rs.Fields("5")    'gr2
        .TextMatrix(i, 6) = rs.Fields("6")    'gr3
        .TextMatrix(i, 7) = rs.Fields("7")    'gr4
        .TextMatrix(i, 8) = rs.Fields("8")    'gr5
        .TextMatrix(i, 9) = rs.Fields("9")    'gr6
        .TextMatrix(i, 10) = rs.Fields("10")  'gr7
        .TextMatrix(i, 11) = rs.Fields("11")  'gr8
        .TextMatrix(i, 12) = rs.Fields("12")  'c1
        .TextMatrix(i, 13) = rs.Fields("13")  'g1
        .TextMatrix(i, 14) = rs.Fields("14")  's3
        .TextMatrix(i, 15) = rs.Fields("15")  'f2
        .CellAlignment = 4
        .TopRow = .Rows - 1
        .Refresh
    End With
    i = i + 1
    rs.MoveNext
Loop

i need to use at least 600,000 cells in MSFlexGrid, so how can i resolve this?


Solution

  • 'I got 15 columns so this makes 21874row * 15column = 328110 cells
    'it blows at 21875th row so 328125th cell is not reachable
    'for that reason i reset the grid so it keeps 
    Do While Not rs.EOF
        With MSFlexGrid1
            If .Rows >= 21874 Then
                .Rows = 2
                .Clear
                i = 1
            End If
            .Rows = .Rows + 1
            .TextMatrix(i, 1) = rs.Fields("1")    's1
            .TextMatrix(i, 2) = rs.Fields("2")    's2
            .TextMatrix(i, 3) = rs.Fields("3")    'f1
            .TextMatrix(i, 4) = rs.Fields("4")    'gr1
            .TextMatrix(i, 5) = rs.Fields("5")    'gr2
            .TextMatrix(i, 6) = rs.Fields("6")    'gr3
            .TextMatrix(i, 7) = rs.Fields("7")    'gr4
            .TextMatrix(i, 8) = rs.Fields("8")    'gr5
            .TextMatrix(i, 9) = rs.Fields("9")    'gr6
            .TextMatrix(i, 10) = rs.Fields("10")  'gr7
            .TextMatrix(i, 11) = rs.Fields("11")  'gr8
            .TextMatrix(i, 12) = rs.Fields("12")  'c1
            .TextMatrix(i, 13) = rs.Fields("13")  'g1
            .TextMatrix(i, 14) = rs.Fields("14")  's3
            .TextMatrix(i, 15) = rs.Fields("15")  'f2
            .CellAlignment = 4
            .TopRow = .Rows - 1
            .Refresh
        End With
        i = i + 1
        rs.MoveNext
    Loop