Solved

copy a file to COM1

Posted on 2004-04-07
6
1,957 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now