String variable size limit not 2GB?

pbassett

Active Member
Joined
May 5, 2004
Messages
358
My code reads files into a string for processing. Today it broke with the error "Run-time error 7 Out of Memory" on a file with LOF (size) 153,344,779 bytes. This is surprising since strings should be allowed up to 2GB. Previous files were easily read by this command:

Dim strFile As String
strFile = Space(LOF(iFileNo)) ' Set File Buffer Size

strFile is Null with this file, however, and this command results in the Error message:

Get iFileNo, , strFile ' Load text [get error Run-time error 7 Out of Memory]

I would greatly prefer using the Get statement to the alternative of the repeated Line Input and redim into an ever-growing array.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,298
Office Version
  1. 365
Platform
  1. Windows
No idea if it'll make a difference but have you tried declaring the variable as Variant, or not typing it at all.

I'm a little confused though, you say that strFile is Null.:eek:

When is it Null? Before/after you've tried to fill it with spaces.

By the way why are you filling it with spaces and what would be the problem with using Line Input, perhaps a little looping too?

Dealing with string as big as that seems, to me anyway, a bit daunting.
 

Watch MrExcel Video

Forum statistics

Threads
1,133,272
Messages
5,657,772
Members
418,412
Latest member
fehr56

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top