关于 Open "LPT1" For Output As #1的使用

hnzzs 2003-08-30 03:31:44
在利用Open "LPT1" For Output As #1打开打印机并往里面写数据时,如果打印机开启则正常,如果打印机关闭或是打印机有错误,则会死机.有什么办法可以让打印机在不能打印的情况下不打印,然后退出去吗?
...全文
867 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
busisoft 2003-08-30
  • 打赏
  • 举报
回复
Win9x下会死机,Win2k下就没有问题
wumy_ld 2003-08-30
  • 打赏
  • 举报
回复
试试这个,它能够马上报错,不用等待。

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
hnzzs 2003-08-30
  • 打赏
  • 举报
回复
kissoflife(明月高楼休独倚,酒入愁肠,化作相思泪!:
改成你的代码,还是不行啊.不知道还有没有其它的解决方法.
wumy_ld 2003-08-30
  • 打赏
  • 举报
回复
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
hnzzs 2003-08-30
  • 打赏
  • 举报
回复
我的代码如下,如果不开打印机一定会程序没有响应的.
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
射天狼 2003-08-30
  • 打赏
  • 举报
回复
没问题啊,我试了,加上错误处理看看~~
soec 2003-08-30
  • 打赏
  • 举报
回复
Open 还能这样用啊, 嘿,新鲜!
Installation and Configuration How to Install the Driver 1) Plug the Cable into a USB port. 2) The “Welcome to the Found New Hardware Wizard” or "Add New Hardware Wizard" (Win98) should appear. If it doesn’t appear, go to step 9. 3) Ensure the product driver CD (included with package) has been inserted in your CD-ROM drive. 4) Select the option: “Install the software automatically (Recommended).” or "Search for the best driver for your device" (Win98) 5) Press “Next”. Win 98 users should check CD-ROM drive. 6) Windows should find the “Prolific USB-to-Serial Comm Port” driver. Otherwise you should find the directory under your version of Windows under the "USB to RS232 1.1" directory on the CD-ROM. Windows 98 lists the device as "GM USB to Serial Bridge" 7) You will probably see a message indicating that the driver has not passed Windows Logo testing. Press “Continue Anyway.” This warning can be safely ignored. 8) Press “Finish” when prompted by Windows to complete the installation. *** If the “Found New Hardware Wizard” did not appear in step 2 *** 9) Open Device Manager by doing the following: a) Click on “Start” and then “Control Panel.” b) Switch to Classic View (if in Category View). c) Double click on “System.” d) Select the Hardware tab. e) Press the “Device Manager” button. 10) Under “Ports (COM & LPT),” look for a USB Device entry with a yellow exclamation point '!' by it. 11) Right click on the USB Device and select “Update Driver.” 12) This should bring up the “Welcome to the Hardware Update Wizard.” 13) Ensure the product driver CD (included with package) is inserted in your CD-ROM drive. 14) Select the option: “Install the software automatically (Recommended).” 15) Press “Next.” Continue from step 5 above. Looking for Drivers? How to Check the Driver Installation 1) Go to the Device Manager: Windows XP: Start -> Control Panel -> System -> Hardware -> Device Manager Windows 2000/2003: Start -> Settings -> Control Panel -> System -> Hardware -> Device Manager Windows 98/ME: Start -> Settings -> Control Panel -> System -> Device Manager 2) Click on the plus sign (+) next to "Ports." 3) If the device is installed properly, you will see "Prolific USB-to-Serial Comm Port. (COMx)" or "USB to Serial Port (COMx)" (Win98). Note that x is the number of the COM port (typically 1-8) assigned to the adapter. The driver is installed properly, but the device is not working First check to see that the Beagle Software application is set to the correct COM port number. To determine the COM port number assigned to the adapter, check the Device Manager (see above). It is also possible that the COM port number assigned is too high. Sometimes a device won't work with the USB-to-Serial adapter even though everything appears to have installed correctly because some computers will only scan a limited number of COM ports. For instance, it is possible that a computers has a limitation of scanning the first four COM ports. If the adapter is installed on COM5, a device with such a limitation will not work until the COM port is reassigned to COM1 - COM4. Windows XP, 2000, ME, and 98 include a function that allows you to reassign the COM port. Simply follow the instructions below: Windows XP port reassignment 1) Follow steps 1 and 2 in "How to Check the Driver Installation." 2) Right click on the "Prolific USB to Serial Port" and click on Properties 3) Click on the "Port Settings" tab. Click the "Advanced" button. 4) Pull down the scrollbar on the bottom, left side and select COM 1, 2, 3 or 4 (NOTE: Choose one that does not say "in use" next to it). Click "OK." 5) Click "OK" again. Notice that the device will show up as being on the same COM port that it was before (i.e., COM5), but will show up on the new port if you close the Device Manager and open it again. 6) Close the device manager. You may have to run the software that came with your device to make it rescan the COM ports. Windows 2000, ME, and 98SE port reassignment 1) Follow steps 1 and 2 in "How to Check the Driver Installation." 2) Right click on the "Prolific USB to Serial Port" and click on Properties 3) Click on the "Port Settings" tab. Click on the Resources tab. 4) Uncheck the box that says "Use automatic settings". 5) Select "Input/Output range". Click on "Change Settings". 6) Type "02E8-02EF" in the Value box. This value will change the port to COM 4. If COM 4 is in use, you must choose another port. The values for each port are: COM 1: 03F8-03FF COM 2: 02F8-02FF COM 3: 03E8-03EF COM 4: 02E8-02EF 7) After entering the value, click OK. Click OK again and click Yes when the "Creating a Forced Configuration" window appears. Click OK again. 8) Restart your computer. If you go into the device manager, you will see that the COM port has changed to the one you have selected.

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧