Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runtime error 14 - out of string space

Status
Not open for further replies.

kskinne

Technical User
Oct 8, 2004
169
0
0
US
I have been quite busy so have not been on the forum for a while. I have the following code in a project that I am using to load the contents of a text file, so that I can make changes to it and save to a new text file.

Code:
Private Sub cmdBrowse_Click()
10    On Error GoTo cmdBrowse_Click_Error
20    MyInitDir = "I:\Tollfiles\EMI - Carroll Metaswitch"
30    With CommonDialog1
40      .CancelError = True
50      .DialogTitle = "Select File"
60      .Filter = "All files (*.*)|*.*|DAT files only (*.dat)|*.dat|EMI files only (*.EMI)|*.EMI|FGD files only (*.fgd)|*.fgd|Text files only (*.txt)|*.txt"
70      .FilterIndex = 1
80      .Flags = cdlOFNHideReadOnly Or cdlOFNOverwritePrompt Or cdlOFNPathMustExist
90      .InitDir = MyInitDir
100     .ShowOpen
110   End With
120   lblCurFilePath.Caption = CommonDialog1.FileName
130   txtNewFile.Text = CommonDialog1.FileName
140   glbOldFileName = CommonDialog1.FileName
150   Open glbOldFileName For Input As #1
160   s = Split(Input(LOF(1), 1), vbCrLf)
170   Close #1
180   glbTotal = UBound(s) + 1
190   lblRecTot.Caption = Format(glbTotal, "#,###,###")
200   Exit Sub
210   On Error GoTo 0
220   Exit Sub
cmdBrowse_Click_Error:
230   MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdBrowse_Click of Form frmEditMeta110101 - Error on line " & Erl
End Sub

I am getting an error on line 170 when it is trying to parse the lines in the file and load them into memory, I presume because the file has too many rows, because the code works fine on smaller text files.

I would like to avoid manually having to split this file into smaller files before processing. Does anyone know of a way that I could update this code, so that it will load this text file in sections and process them one at a time? This may also affect how the rest of my code runs, and I may then need to post back with that code, but I figured I would start here. Any help is much appreciated.

Thank you,
Kevin
 
What error occurs?

The only thing I see that might fail is the case where the file is empty.
 
I believe the title of the thread tells us that ... ;-)
 
The only thing I see that might fail is the case where the file is empty."

I don't think so, at least not in this case. EmptyFile.txt is empty.

Code:
Dim s() As String
Open "C:\EmptyFile.txt" For Input As #1
s = Split(Input(LOF(1), 1), vbCrLf)
Close #1
 
Sorry about two posts. I saw this:

The MSDN has this explanation :


******************************************************
Out of string space (Error 14)
Your system may have run out of memory, which has prevented a string from being allocated. Similarly, expressions requiring that temporary strings be created for evaluation may be causing this error. For example, the following code will cause an Out of string space error:



MyString = "Hello"
For Count = 1 To 100
MyString = MyString & MyString
Next Count


Visual Basic lets you allocate a string with a maximum length of 65,535 characters. However, in executing statements at run time, the host application needs to use some string space for overhead. The amount of overhead varies among hosts, but should not exceed 50 bytes. If you need to allocate a string of the maximum length your host can support, reduce the string size by 50 bytes, then increase the length incrementally until this error is generated again. The value immediately preceding the error represents the host's maximum string length.



Dim MyString As String * 65485
' Start with (65535-50).
' On successive runs, increment
' length until "Out of string
' space" error occurs.

Sub MySub
MyString = "string" ' Error occurs here when the
End Sub ' maximum length is exceeded.

here
 
If the file is much bigger than 350MB or so (double for Unicode data) VB6 will hit an Out of Memory error anyway. That's because 700MB of raw String data plus descriptors and such puts you up against the wall.

It depends on how you accomplish the "split" but using the Split() function may have limitations in the way it allocates the substrings. Some alternatives use 2 passes to find the delimiters while others use a Long array to grab them and then use that data to size the final array and then extract substrings. Using 2 passes saves you that extra array and so you have a little more wiggle room for a larger input file.

See for ideas.

I tried implementing their SplitC01, but removing the problematic use of SysAllocStringLen (perhaps I had goofed?) and using Mid$() instead. I also did the reading and splitting on chunks of data instead of the entire file, which meant more Redim Preserve calls and copying but at least saved having to have 2 copies of the entire file data in RAM at once.

The blocksize I used was 65536 bytes or filebytes\50, whichever was larger.

Worked just fine up to 25,000,000 lines or so of 12 chars plus CRLF each (ANSI file on disk around 333MB). Much larger led to Out of Memory. Performance was quite acceptable.
 
I apologize for just getting back to the replies on this post - the file size is 232,581 KB.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top