vb6.0 快速读取txt

前端之家收集整理的这篇文章主要介绍了vb6.0 快速读取txt前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Function GetFile(FileName As String) As String
Dim i As Integer,s As String,BB() As Byte
If Dir(FileName) = "" Then Exit Function
i = FreeFile
ReDim BB(FileLen(FileName) - 1)
Open FileName For Binary As #i
Get #i,BB
Close #i
s = StrConv(BB,vbUnicode)
GetFile = s
End Function

'调用举例:
dim s as string
s=GetFile("c:\1.txt")
如果文件中没有中文字符,那么下面代码读整个文件的速度是非常快的,我读了一个6M的文件,只用了不到1秒。如果有中文字符,就需要把s = Input$(LOF(1),#1)中的LOF(1)减去中文字符数量。
Dim r As String,s As String
r = Environ("userprofile")
r = r + "\桌面\9898.txt"'要读的文件路径,在桌面上的9898.txt
Open r For Input As #1
s = Input$(LOF(1),#1)
Debug.Print s
Close #1
原文链接:https://www.f2er.com/vb/258833.html

猜你在找的VB相关文章