我想对软盘驱动器操作,当没有软驱中没有软盘时,出现没有软盘的提示框,软盘没有放好时也出现提示框.根据所找到的资料
函数为:
Function FileExists(filename) As Boolean
Dim Msg As String
'如果检测到任何一个错误,则开始捕获错误,从而响应错误处理程序。
On Error GoTo CheckError
FileExists = (Dir(filename) <> "")
'如果未出现错误,则避免使用错误处理程序。
Exit FunctionCheckError: '如果出现错误,则在此分枝。
'定义常数以表示固定的 Visual Basic 错误代码。
Const mnErrDiskNotReady = 71, _
mnErrDeviceUnavailable = 68
' vbExclamation、vbOK、vbCancel、vbCritical 和 vbOKCancel 是
'定义在 VBA 类型库中的常数。
If (Err.Number = mnErrDiskNotReady) Then
Msg = "Put a floppy disk in the drive "
Msg = Msg & "and close the door."
'显示具有感叹号图标以及“确定”和“取消”按钮的消息框。
If MsgBox(Msg, vbExclamation & vbOKCancel) = _
vbOK Then
Resume
Else
Resume Next
End If
ElseIf Err.Number = mnErrDeviceUnavailable Then
Msg = "This drive or path does not exist: "
Msg = Msg & filename
MsgBox Msg, vbExclamation
Resume Next
Else
Msg = "Unexpected error #" & str(Err.Number)
Msg = Msg & " occurred: " & Err.Description
' 用“Stop”信号灯图标和“确定”按钮显示消息框。
MsgBox Msg, vbCritical
Stop
End If
Resume
End Function
这是MSDN中的函数
我定义一个单击事件引用这个函数,可是死机了
Private Sub Command2_Click()
Dim a As String
Dim b As String
Dim sorce As String
Dim destination As String
'Dim msg As String
sorce = "d:\rw\data\" & b
destination = "a:\" & b
If FileExists(destination) = True Then
FileCopy sorce, destination
End If
End Sub
不知哪位高人可以指点一二
我是初学VB,惭愧,拜托了
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货