hn4u @ Last updated 21/11/04 22:42
Go to my homepage at http://4u.jcisio.com
Full version available at http://4u.jcisio.com/r/article384.htm

Không rõ

Nạp một nội dung tập tin nhanh

Module này sẽ nạp một tập tin rất nhanh. Nó sử dụng một mảng kích thước 50000 byte để nạp tập tin rất nhanh. Bạn có thể sử dụng để thay thế các hàm bạn thường dùng nhưng không tối ưu. Bạn có thể thử ví dụ của chúng tôi để thử nghiệm kỹ thuật này.

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


hainam4u @ Last updated 21/11/04 22:42
Go to my homepage at http://4u.jcisio.com