A1VBCode Forums

Out of memory error while loading to flexgrid...


http://www.a1vbcode.com/vbforums/Topic9950.aspx

By desperado1975 - 3/27/2005

Hello there,

i was trying to load text files(tab delimited) in a flexgrid, i tried two methods to add each line in the grid, the procedure was fine with small files; but once i load a big file (some of my text files are 100,000+ rows) i get out of memory error (#7) ...
is there any way to handle this error and continue loading the file where it stoped?

my loading code looks like this:

Sub cmdBtnDXP_Click()

InitMSHFlexGrid1 ' to set number of columns


' first method

Dim hFile As Integer
Dim sLines() As String, sTxt As String
Dim n As Double, nCount As Double
With CommonDialog1
    .CancelError = True
    .Flags = cdlOFNFileMustExist + cdlOFNHideReadOnly
    .Filter = "Data Exported Files (*.DXP - *.TXT)|*.DXP;*.TXT|All Files (*.*)|*.*|Text Files (*.txt)|*.txt|"
    On Error Resume Next
    .ShowOpen
    If Err.Number <> cdlCancel Then
       
        hFile = FreeFile
        Open .FileName For Input As #hFile
        sTxt = Input(LOF(hFile), hFile)
        Close #hFile
        sLines = Split(sTxt, vbCrLf)
       
        nCount = UBound(sLines)
        For n = 1 To nCount
        MSHFlexGrid1.AddItem sLines(n)
      
        Next
    End If
End With

'Secon method
Dim intFile As Integer

intFile = FreeFile
CommonDialog1.ShowOpen
Open CommonDialog1.FileName For Input As #intFile
Do While Not EOF(1)
Line Input #intFile, textLine
MSHFlexGrid1.AddItem textLine
Loop
Close #intFile
End If

End Sub


many thanks..

By s.p.i.d.e.r.m.a.n - 4/1/2005

Hi! Desperado

See.. when the problem is with FLexGrid itself there is no need using Recordset (wat Mark said).

You will have to replace FlexGrid with sum other control.

Try using RichTextBox because even Simple Text Box has 64kb limitation.

Display the into RichTextBox

Bye...