vb6快速读取txt

| |
[不指定 2021/11/12 12:36 | by admin ]
一、快速读取txt,空白内容则会出错。
1、建立模版
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



2、窗体调用举例:
dim s as string
s=GetFile("c:\1.txt")
Text1 = s


3、如果文件中没中文字符,那么下面代码读整个文件速度是非常快的,我读了一个6M文件,只用了不到1秒,如果有中文字符,就需要把减去中文字符数量。
s = Input$(LOF(1), #1)中的LOF(1)  
Dim r As String, s As String
r = Environ("userprofile")
r = r + ""c:\1.txt"    
Open r For Input As #1
s = Input$(LOF(1), #1)
Debug.Print s
Close #1


二、(另外一种方法)空白文件照样读取,这种方法比较好。


三、(第三种方法)一行代码读入,空白内容也会出错。


四、数据查找InStr含数

VB6编程 | 评论(0) | 引用(0) | 阅读(2672)
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
昵称   密码   游客无需密码
网址   电邮   [注册]
               

验证码 不区分大小写