首页 /编程语言和算法/VB6/VBA/ASP
 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


 
全部回复(0)
首页 | 电脑版 |