Error 14 Out of String Space *RESOLVED*
I am using the split function to parse data out of text files. I am now having a problem with one of the text files that I am reading. The problem is that the file is 114 megs, and this is where the "out of string space" error is coming from. Below is a sample of the code that I am using. Once the lines() array is populated I can iterate through the array and parse the data I need. Is there another way to read this information into an array like I am doing with the split function using the lines() array? If not does any one have any other suggestions?
As always, thanks in advance.
Michael
lines() = Split(ReadFile(TextFile), vbCrLf)
Public Function ReadFile(filename As String) As String
Dim isopen As Boolean
'Open file and assign a filenumber
fnum = FreeFile()
Open filename For Binary As #fnum
isopen = True
ReadFile = Input(LOF(fnum), fnum)
End Function
Error 14 Out of String Space *RESOLVED*
I found the problem...
The carrier that we get the file from changed something in it. I now have a fixed length delimited file that appears to be dumped as a single line with vbcrlfs embedded. I resorted to "Chunking" it by the record length and stripping away the vbcrlfs. The processing is now going as smoothly as ever.
Re: Error 14 Out of String Space *RESOLVED*
Hi, Michael
I got the same issue with your. But I do not understand your solution. Can you help to give me more details about it? It will be better that post your code here.
Re: Error 14 Out of String Space *RESOLVED*
To be honest, this was so long ago I forgot about it. However, it seems like I used the solution mentioned by muddy a few posts up and read the file in chuncks.
Re: Error 14 Out of String Space *RESOLVED*
Using byte arrays is a more efficient way to read a bigger file:
Code:
Dim bytFile() As Byte, FF As Integer
FF = FreeFile
Open "test.txt" For Binary Access Read As #FF
ReDim bytFile(0 to LOF(FF) - 1)
Get #FF, , bytFile
Close #FF
If you only need to get a partial position from the byte array as a string, you can use the following API function to do it:
Declare Function ByteString Lib "oleaut32" Alias "SysAllocStringByteLen" (Ptr As Byte, ByVal Length As Long) As String
So if your file contains the text "ABCDE" and you use a line like this:
MsgBox ByteString(bytFile(1), 3)
You will see a message box with letters "BCD". Remember, index 0 = first byte.
Making the entire byte array a string can be done like this:
strFile = StrConv(bytFile, vbUnicode)
Erase bytFile
Remember though that this is only good for textual data and with big files you may get the string space error again. Also, using this for binary files can be harmful, because bytes (0 – 255) will result in different character codes (especially often in the 128 – 255 range) and the results depend on which locale the code is executed.