VB读取文件的问题
发布网友
发布时间:2023-12-21 06:46
我来回答
共3个回答
热心网友
时间:2024-01-17 07:00
进度条到一半就停了,这个一点也不奇怪,filelen是文件的字节总数,一个汉字是两个字节,而处理时用len,是统计的字符个数,一个汉字就是一个字符,所以要改用LenB来统计字节个数
文本框里,结果显示不全,文本框能处理的最大长度为65535个字符(粘贴进去的除外),读入的文本长度比这个长,肯定会显示不全的,这个要显示全,自己酌情添加文本框吧
Public Sub readfile(ByVal FileLocation As String)
With ProgressBar1
.Max = FileLen(FileLocation)
.Min = 0
.Value = 0
End With
Dim InputStr As String, WholeFile As String
Open FileLocation For Input As #1
Do While Not EOF(1)
Line Input #1, InputStr
DoEvents
WholeFile = WholeFile & InputStr & vbCrLf
ProgressBar1.Value = LenB(StrConv(WholeFile, vbFromUnicode))
Loop
Close #1
Text1 = WholeFile
End Sub
Private Sub Command1_Click()
readfile "d:\小说.txt"
MsgBox "OK!"
End Sub
热心网友
时间:2024-01-17 07:01
Private Sub Command1_Click()
readfile "z:\1.txt"
End Sub
Public Sub readfile(ByVal FileLocation As String)
ProgressBar1.Max = FileLen(FileLocation)
Dim InputStr As String, WholeFile As String
Open FileLocation For Input As #1
Do While Not EOF(1)
Line Input #1, InputStr
WholeFile = WholeFile & InputStr & vbCrLf
ProgressBar1.Value = ProgressBar1.Value + Len(InputStr)
Loop
Close #1
Text1.Text = WholeFile
End Sub
热心网友
时间:2024-01-17 07:01
filelen测试的是字节数
len测试的是字符数,两者在有中文的情况下是不等的~~