WARNING: If anything else prints on the printer attached to COM1, your program may not work as expected.
- Add the following code to the General Declarations section of Form1:
Private Declare Function DefineDosDevice Lib "kernel32" Alias _
"DefineDosDeviceA" (ByVal dwFlags As Long, ByVal lpDeviceName _
As String, ByVal lpTargetPath As String) As Long
Const DDD_RAW_TARGET_PATH = &H1
- Add another Command button to Form1.
- Add the following code in the Click event of Command2:
DefineDosDevice DDD_RAW_TARGET_PATH, "COM5", "\Device\Serial0"
- Change the code on Command1 to open COM5:
MSComm1.CommPort = 5
- Run the program, click Command2, and then click Command1.
Steps to Reproduce the Behavior
- Install a Generic Text printer, and then connect it to COM1 instead of LPT1.
- Start a new Standard EXE project in Microsoft Visual Basic. By Default, Form1 is created.
- Add the Microsoft Comm Control to the project.
- Add a new MSComm1 control on Form1.
- Add a new Command button on Form1, and then insert the following code in the Click event:
MSComm1.CommPort = 1
MSComm1.Settings = "9600,N,8,1"
MSComm1.Handshaking = comNone
MSComm1.InBufferSize = 1024
MSComm1.OutBufferSize = 512
MSComm1.RThreshold = 0
MSComm1.SThreshold = 0
MSComm1.InputLen = 0
MSComm1.PortOpen = True
- Run the program, and then click Command1.
ID do Artigo: 318832 - Última Revisão: 19 de jun de 2014 - Revisão: 1