Loading Huge Files

l is set to 2k, 2*1024.  this is the buffer size, ie: how much to load in each go
strFile is the name of the file to open.

Dim l as long, sz as long
Dim FN As Integer
Dim strFile As String, c As String
FN = FreeFile
Open strFile For Binary Access Read As #FN
   l = 2 * 1024: c = Space$(l)    ' 2k Buffer Size,  2 * 1024
   sz = LOF(FN)
   If sz / l Then
       For d = 1 To sz / l
           Get #FN, , c
           MsgBox c
   End If

' load remainder of file, if filesize is not exactly divisable by l (2k)
   l = sz Mod l
   If l Then
       c = Space$(l)
       Get #FN, , c
       MsgBox c
   End If
Close #FN

The data loaded is returned in variable c. Do whatever you like with it..

You might also like...


Kym Manson Till the Roof comes off Till the Lights go out Till my Legs give out Can't shut my mouth I will not fall, my Wisdoms all.


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Beware of bugs in the above code; I have only proved it correct, not tried it.” - Donald Knuth