Function ReadtxtFile(strPathName As String) As String
On Error GoTo Exit_Err
Dim strFile As String
Open strPathName For Input As #1
ReadtxtFile = ""
strFile = ""
Do While Not EOF(1)
Line Input #1, strFile ' = Input(1, #1)
if ReadtxtFile="" then
ReadtxtFile = strFile
else
ReadtxtFile = ReadtxtFile & vbCrLf & strFile
end if
Loop
Close #1
Exit Function
Exit_Err:
MsgBox Err.Description
Exit Function
End Function
调用方法:
Private Sub 命令4_Click()
Me.txt1 = ReadtxtFile("c:\file1.txt")
End Sub