关于vb中读取文本文件时,提示用户“读取失败”

来源:百度知道 编辑:UC知道 时间:2024/06/14 17:15:46
要求:编写一个程序,输入文件名,单击打开后,如果找不到相应文件,则msgbox "error"
请提供代码~

Public Function FileExists(filename As String) As Boolean
On Error GoTo Errhandle
Dim i As Integer
i = 0
i = Len(Dir$(filename))
If i = 0 Or Err Then
FileExists = False
Else
FileExists = True
End If
Exit Function
Errhandle:
FileExists = False
End Function

Private Sub Command1_Click()
if dir("文件名")="" then msgbox "error"
End Sub