Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


Out of memory error while loading to flexgrid...


Out of memory error while loading to flexgrid...

Author
Message
desperado1975
desperado1975
Forum God
Forum God (390 reputation)Forum God (390 reputation)Forum God (390 reputation)Forum God (390 reputation)Forum God (390 reputation)Forum God (390 reputation)Forum God (390 reputation)Forum God (390 reputation)Forum God (390 reputation)

Group: Forum Members
Posts: 2, Visits: 1

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..


DOS
DOS
Forum God
Forum God (29K reputation)Forum God (29K reputation)Forum God (29K reputation)Forum God (29K reputation)Forum God (29K reputation)Forum God (29K reputation)Forum God (29K reputation)Forum God (29K reputation)Forum God (29K reputation)

Group: Forum Members
Posts: 189, Visits: 25
Cant do anything to fix it if your out of memory...

Well, you could try increasing the virtual memory from your program to what is needed, but iv not got a clue how youd do that.

DOS





email me
Mark
Mark
Forum God
Forum God (141K reputation)

Group: Moderators
Posts: 1.1K, Visits: 11K

I haven't tried this so it is only random thoughts.

I would try opening the text file and adding the contents to an ADO recordset. Then set the data source of the FlexGrid to that recordset.


johnboy891
johnboy891
Forum God
Forum God (80K reputation)Forum God (80K reputation)Forum God (80K reputation)Forum God (80K reputation)Forum God (80K reputation)Forum God (80K reputation)Forum God (80K reputation)Forum God (80K reputation)Forum God (80K reputation)

Group: Forum Members
Posts: 545, Visits: 1K

you know... you could use the filesystem object in that FOR loop and eliminate the split function (although it's fun to use).  do this...

(after dimming and setting, of course)

do until fso.atendofstream
     MSHFlexGrid1.AddItem fso.readline
Next

i love the fso... and while that method will be reading and accessing the text file every time it loops (causing a slight performance issue), you will not have to load your memory up with 100,000 lines of text.  but... question... maybe i am saying all this for naught.. cuz i think you would still have a memory issue even with the listbox containing that much data.  at least this method will cut that memory usage in half (ie, won't have a full array and a full listbox).

if the performance is too slow to justify using that method on account of only a few large files every once in awhile, trap the memory error number and use an IF statement that says If Err.Number = 40 Then *code to run above FSO loop.  that way it will be off to the bat loop as a backup.

hey... you know, or go buy a gig stick.


desperado1975
desperado1975
Forum God
Forum God (390 reputation)Forum God (390 reputation)Forum God (390 reputation)Forum God (390 reputation)Forum God (390 reputation)Forum God (390 reputation)Forum God (390 reputation)Forum God (390 reputation)Forum God (390 reputation)

Group: Forum Members
Posts: 2, Visits: 1

Many thanks guys,

 

i checked again on this issue, i found out the reason here:

http://support.microsoft.com/default.aspx?kbid=191006

It is limited to 350,000 cells only ...

the file i was loading was 68 Cols * 6000 Rows = 408,000 > 350,000 cells

since this was not working, i have to switch to what Mark suggested, the problem is that i'm a newbi and not sure how to do the procedure of opening the text and connect it to the flexgrid.I would really appreciate your help in this

again many thanks & regards to all


s.p.i.d.e.r.m.a.n
s.p.i.d.e.r.m.a.n
Forum God
Forum God (6.7K reputation)Forum God (6.7K reputation)Forum God (6.7K reputation)Forum God (6.7K reputation)Forum God (6.7K reputation)Forum God (6.7K reputation)Forum God (6.7K reputation)Forum God (6.7K reputation)Forum God (6.7K reputation)

Group: Forum Members
Posts: 58, Visits: 109

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...



s.p.i.d.e.r.m.a.n


GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search