Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

copy a file to COM1

Posted on 2004-04-07
6
Medium Priority
?
2,031 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 26

Accepted Solution

by:
EDDYKT earned 2000 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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

972 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