Library code snippets
Loading Huge Files
By Kym Manson, published on 12 Mar 2002
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..
Related articles
Related discussion
-
Problem with migration to C# (CoCreateInstanceEx)
by LRollison (1 replies)
-
VB6 Problem Creating Shortcuts
by rb1177 (0 replies)
-
how can i open a file
by kyawswarhtun (0 replies)
-
how to save any one form what i want?
by blackguy (5 replies)
-
Build an MP3 Player
by soybees (4 replies)
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...
I'll correct the code.
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)
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
This thread is for discussions of Loading Huge Files.