Antrach
asked on
copy a file to COM1
How do I copy a file from the hard drive to COM1: in VB6?
You need to use the MSCOMM controls.
MSComm control works quite well for this:
Add it to your components and place an instance on the form:
Private Sub Form_Load()
With MSComm1
.Settings = "9600,n,8,1"
.CommPort = 1
.PortOpen = True
End With
End Sub
Private Sub Form_Unload()
MSComm1.PortOpen = False
End Sub
Private Sub cmdSend_Click()
MSComm1.Output = "Hello this is text out"
End Sub
Private Sub cmdReceive_Click()
Dim strInput As String
strInput = MSComm1.Input
MsgBox strInput
End Sub
This is the simplest method of using the control as you are only sending and receiving on demand. The control has a single event _OnComm() which will allow you to run in an event-driven mode.
Add it to your components and place an instance on the form:
Private Sub Form_Load()
With MSComm1
.Settings = "9600,n,8,1"
.CommPort = 1
.PortOpen = True
End With
End Sub
Private Sub Form_Unload()
MSComm1.PortOpen = False
End Sub
Private Sub cmdSend_Click()
MSComm1.Output = "Hello this is text out"
End Sub
Private Sub cmdReceive_Click()
Dim strInput As String
strInput = MSComm1.Input
MsgBox strInput
End Sub
This is the simplest method of using the control as you are only sending and receiving on demand. The control has a single event _OnComm() which will allow you to run in an event-driven mode.
So as you can see... to send a file it would be easily accomplished with.
the following code will open a MSComm control and send a text file line by line over comm 1.
With MSComm1
.Settings = "9600,n,8,1"
.CommPort = 1
.PortOpen = True
End With
dim data as string
Open "File.txt" for input as #1
do while eof(1) = false
line input #1,data
MSComm1.Output = data
loop
close #1
MSComm1.PortOpen = False
the following code will open a MSComm control and send a text file line by line over comm 1.
With MSComm1
.Settings = "9600,n,8,1"
.CommPort = 1
.PortOpen = True
End With
dim data as string
Open "File.txt" for input as #1
do while eof(1) = false
line input #1,data
MSComm1.Output = data
loop
close #1
MSComm1.PortOpen = False
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
or just
shell "copy HardDriveFile com1:"
shell "copy HardDriveFile com1:"
ASKER
MSComm component worked well sending a text string out the comm port, but did not work attempting to mimic a filecopy command. The Do-While loop had no effect on the serial printer.