找到原因了,因为新建的文件是空的,所以就出错,加个判断就好了,做个记录,以备后查
程序代码:
Function GetFile(FileName As String) As String '用来秒加载文本文件的
Dim i6 As Integer, s6 As String, BB() As Byte
If Dir(FileName) = "" Then Exit Function
i6 = FreeFile
Dim FileLength '// 打开文件
Open FileName For Input As #19 '// 取得文件长度
FileLength = LOF(19) '// 如果长度为 0,那么就是空的咯
If FileLength <> 0 Then
'// 空的
Close #19
ReDim BB(FileLen(FileName) - 1)
Open FileName For Binary As #i6
Get #i6, , BB
Close #i
s6 = StrConv(BB, vbUnicode)
GetFile = s6
'调用举例(按钮等执行):
'Dim s6 As String
's6 = GetFile("d:\1.txt")
'Text1 = s
End If
End Function