查看: 10  |  回复: 0
  VB6 不用Dir测试打开文件,如果文件不在也不出错
楼主
发表于 今天 18:46

新建From1(窗体),新建Command1(按钮CommandButton),代码:

Private Sub Command1_Click()
    Dim intFileNum%: intFileNum = FreeFile
    On Error Resume Next
    Open App.Path & "\abc.txt" For Input As #intFileNum
        If Err.Number <> 0 Then
            MsgBox "无法打开文件!", vbCritical, "失败"
            Exit Sub
        End If
    On Error GoTo 0
End Sub


您需要登录后才可以回帖 登录 | 立即注册
【本版规则】请勿发表违反国家法律的内容,否则会被冻结账号和删贴。
用户名: 立即注册
密码:
2020-2025 MaNongKu.com