Solved

copy a file to COM1

Posted on 2004-04-07
6
1,977 Views
Last Modified: 2006-11-17
How do I copy a file from the hard drive to COM1: in VB6?
0
Comment
Question by:Antrach
  • 3
  • 2
6 Comments
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 10777231
You need to use the MSCOMM controls.


0
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 10777239
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.
0
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 10777256
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
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 26

Accepted Solution

by:
EDDYKT earned 500 total points
ID: 10777375
Does this work?

dim FileInfo
open "HardDriveFile" for input as #1
open "Com1:" for output as #2
while not eof(1)
 line input#1, FileInfo
 print #2, FileInfo
wend
close #1
close #2
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 10777398
or just

shell "copy HardDriveFile com1:"
0
 

Author Comment

by:Antrach
ID: 10782976
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.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question