I'm writing a notepad-type application that will support files larger than the notepad limit, and I'm having trouble. It actually runs out of memory before it can even finish reading a file as small as 68KB.
Anyone have any tips or pointers on how to (quickly [if possible]) open a file of any size (or at least files up to 1 MB)? Is there any API that I could use?
My current method of retrieving the file contents is this:
Code:Private Sub mnuOpen_Click() On Error GoTo Cancel: UpdateStatus "Open a file..." CommonDialog1.FLAGS = cdlOFNLongNames CommonDialog1.DialogTitle = "Advanced Text Editor - Open File" CommonDialog1.ShowOpen X$ = CommonDialog1.FileName ' ' 'this is what actually inputs the file ' ' Open X$ For Binary As #1 Text1.Text = "" L = LOF(1) Text1.Text = Input(L, 1) ' 'everything else is just junk ' P = 1 lastpos = 1 While P <> 0 P = InStr(lastpos + 1, X$, "\") If P <> 0 Then lastpos = P Wend thefile$ = Right(X$, Len(X$) - lastpos) ThePath$ = Left(X$, lastpos - 1) UpdateTitle thefile$ UpdateStatus "File loaded successfully" Changed = False Cancel: Close If Err = 7 Then MsgBox "Out of memory", vbCritical, "Error" UpdateStatus "Error loading file: Out of memory" ElseIf Err <> 0 Then UpdateStatus "File not opened. Reason: " & Error(Err) End If End Sub




.
Reply With Quote