Library code snippets

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

Comments

  1. 14 Mar 2002 at 08:17
    Sorry SenGoku. I asked mike to change the variable names such as (File$) to just (Dim File As String). However, it appears he's gone and changed some other bits that he shouldn't have

    I'll correct the code.
  2. 14 Mar 2002 at 06:28
    dont change my fucking code.  it worked perfectly  or post your own version

    strC = strSpace(FN)   should be   strC=Space$(l)

    in fact strC is wrong, because it ain`t declared as a String, which means its defaulted to variant, so it should be varC



    Heres the original code..

    File$ is the filename or variable holding the filename
    Data is returned in Variable c$ (String) ($ = String DataType)

    Code:

    Dim l as long, sz as long

                      Open File$ For Binary Access Read As #1
                       l = 1024: c$ = Space$(l)
                       sz = LOF(1)
                       
                       If sz / l Then
                           For d = 1 To sz / l
                               Get #1, , c$
                               MsgBox c$            ' Do whatever with the inputted data
                           Next
                       End If

    ' Load remainder of file, if FileSize (sz) is not exactly divisable by l (2k, BufferSize)
                       l = sz Mod l
                       If l Then
                           c$ = Space$(l)
                           Get #1, , c$            ' Do whatever with the inputted data
                           MsgBox c$
                       End If
                   Close #1
  3. 01 Jan 1999 at 00:00

    This thread is for discussions of Loading Huge Files.

Leave a comment

Sign in or Join us (it's free).

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.

Related discussion

Related podcasts

  • Christian Beauclair

    14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...

We'd love to hear what you think! Submit ideas or give us feedback