VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This module will load a file VERY FAST!!! It uses an array sized in 50000 byte elements to load a f

by JerBer Applications (1 Submission)
Category: Files/File Controls/Input/Output
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Sat 14th October 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This module will load a file VERY FAST!!! It uses an array sized in 50000 byte elements to load a file very quickly. It also will write the

API Declarations


Public num As Long
Public filedata() As String

Rate This module will load a file VERY FAST!!! It uses an array sized in 50000 byte elements to load a f



'a pretty fast looping technique. This will load a file A LOT
'faster than a regular 'filedata = filedata & newfiledata' type
'loop. The filedata variable is public, so your project can use
'it anywhere else after the file has been loaded. The subs are
'self explanatory: send a file name to the write or load subs
'to write or load that file - the filename must have a complete
'path.

'Note: The filedata variable is an array, each element being
'50000 characters long, unless the file is not divisible by
'50000. So, the filedata has the file broken up into pieces,
'and you must remember that your file may not fit into one element
'of the array.

'PS: I know this may not be a very efficient module - however,
'I am sixteen years old, so I'm still learning. ;-)

Public Sub LoadFile(filename As String)
Dim SmallFile As Boolean
SmallFile = False
FiftyLen = FileLen(filename) / 50000
If FiftyLen = 0 Then
SmallFile = True
FiftyLen = 1
End If
Form1.pb.Max = 1
ReDim filedata(FiftyLen) As String
num = 0
While num <> FiftyLen + 1
filedata(num) = Space(50000)
num = num + 1
Wend
FileNum = FreeFile
num = 1
Open filename For Binary As FileNum
Get FileNum, 1, filedata(0)
While num <> (FiftyLen + 1)
num = num + 1
Get FileNum, , filedata(num - 1)
Form1.pb.Value = (num - 1) / FiftyLen
DoEvents
Wend
Close FileNum
Dim tempstr As String
If SmallFile = False Then
temp = FileLen(filename) - (50000 * FiftyLen)
End If
If temp > 0 Then
tempstr = Mid(filedata(FiftyLen), 1, temp)
filedata(FiftyLen) = ""
filedata(FiftyLen) = tempstr
Else
temp = 50000 - (50000 * FiftyLen) - FileLen(filename)
temp = (-1) * temp
tempstr = Mid(filedata(0), 1, temp)
filedata(0) = ""
filedata(0) = tempstr
FiftyLen = 0
End If

End Sub

Public Sub WriteFile(filename As String)
FileNum = FreeFile
num = 0
Open filename For Binary As FileNum
Put FileNum, 1, filedata(0)
While num <> (FiftyLen)
num = num + 1
Put FileNum, , filedata(num)
Form1.pb.Value = (num) / FiftyLen
DoEvents
Wend
Close FileNum
End Sub

Download this snippet    Add to My Saved Code

This module will load a file VERY FAST!!! It uses an array sized in 50000 byte elements to load a f Comments

No comments have been posted about This module will load a file VERY FAST!!! It uses an array sized in 50000 byte elements to load a f. Why not be the first to post a comment about This module will load a file VERY FAST!!! It uses an array sized in 50000 byte elements to load a f.

Post your comment

Subject:
Message:
0/1000 characters