Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Runtime error 14 - out of string space

Runtime error 14 - out of string space

Runtime error 14 - out of string space

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.


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

RE: Runtime error 14 - out of string space

How big is the file?

RE: Runtime error 14 - out of string space

What error occurs?

The only thing I see that might fail is the case where the file is empty.

RE: Runtime error 14 - out of string space

I believe the title of the thread tells us that ... winky smile

RE: Runtime error 14 - out of string space

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


Dim s() As String
Open "C:\EmptyFile.txt" For Input As #1
s = Split(Input(LOF(1), 1), vbCrLf)
Close #1 

RE: Runtime error 14 - out of string space

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 http://www.vbforums.com/showthread.php?86661-Out-o...

RE: Runtime error 14 - out of string space

I repeat: how big is the file?

RE: Runtime error 14 - out of string space

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 http://www.xbeat.net/vbspeed/c_Split.htm 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.

RE: Runtime error 14 - out of string space

I apologize for just getting back to the replies on this post - the file size is 232,581 KB.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close