Private Sub Cmdtry_Click()
On Error GoTo ErrMsg
If Trim(Txtcommand.Text) = "" Then
MsgBox "请输入弹出钱箱的命令代码!", vbInformation
Txtcommand.SetFocus
Exit Sub
End If
Printer.Print Txtcommand.Text
Printer.EndDoc
Exit Sub
ErrMsg:
MsgBox "打印机错误或是弹出钱箱的命令代码有误!", vbInformation
End Sub
Private Sub Cmdtry_Click()
On Error Resume Next'关闭错误陷阱
If Trim(Txtcommand.Text) = "" Then
MsgBox "请输入弹出钱箱的命令代码!", vbInformation
Txtcommand.SetFocus
Exit Sub
End If
Open "LPT1" For Output As #1
If Err.Number<>0 Then GoTo ErrMsg'如果有错误就跳到错误处理
'弹出钱箱
Print #1, Txtcommand.Text
Close #1
Exit Sub
ErrMsg:
On Error Resume Next
MsgBox "打印机错误或是弹出钱箱的命令代码有误!", vbInformation
Exit Sub
End Sub
我的代码如下,如果不开打印机一定会程序没有响应的.
Private Sub Cmdtry_Click()
On Error GoTo Err
If Trim(Txtcommand.Text) = "" Then
MsgBox "请输入弹出钱箱的命令代码!", vbInformation
Txtcommand.SetFocus
Exit Sub
End If
Open "LPT1" For Output As #1
'弹出钱箱
Print #1, Txtcommand.Text
Close #1
Exit Sub
Err:
On Error Resume Next
MsgBox "打印机错误或是弹出钱箱的命令代码有误!", vbInformation
Exit Sub
End Sub