i have been trying to make a program to transfer any kind of files through serial port using VB6, i was able to transfer the text file but not other files so please help me on this

Dani AI

Generated

had the classic symptom for a text-vs-binary problem: text transfers OK, other files get corrupted. was on the right track about handling different file types, but the concrete fix in VB6 is to treat files as binary and send raw bytes over the COM port (not do text I/O or rely on VB strings for raw data).

A practical workflow:

  • Open the file For Binary, read it into a Byte() array.
  • Send that byte array over the serial port (MSComm.Output accepts a byte array).
  • On the receiver, read the incoming bytes and write them For Binary.

Example (sender/receiver snippets):

' Sender (VB6)
Dim data() As Byte
Open filePath For Binary Access Read As #1
ReDim data(LOF(1) - 1)
Get #1, , data
Close #1
MSComm1.Output = data
' Receiver (VB6 - e.g. in OnComm)
Dim rec As Variant
rec = MSComm1.Input
Open outPath For Binary Access Write As #1
Put #1, , rec
Close #1

Troubleshooting and reliability tips:

  • Do not use Print#, Write#, or any text-mode file I/O for binary files; they alter bytes (CR/LF and encoding).
  • Send in chunks (for example 1 KB to 4 KB) rather than one huge block, and use hardware flow control (RTS/CTS) or an application-level ACK so buffers do not overflow.
  • Prefix each transfer with a simple header (length or filename) and include a checksum (CRC32 or simple CRC16) so the receiver can verify and request retransmit on error.
  • Test with a small binary (jpg or exe) and compare byte-for-byte on both ends to confirm correctness.

If transfers still fail, post the exact file I/O and MSComm settings (baud, parity, handshake) and whether hardware flow-control lines are wired; that information narrows common causes like incorrect settings, buffers, or line wiring.

Recommended Answers

All 2 Replies

Please post what you've done so far, so people can have a look at what's wrong.

i have been trying to make a program to transfer any kind of files through serial port using VB6, i was able to transfer the text file but not other files so please help me on this

The first step is to develop a program / code that can read all types of files. That can be a rather daunting task to accomplish. So break it down. First decide just what types / formats you need or want to transfer "Make a LIST" and write seperate routines for each.
Use a Case / Select case in VS2008 to call the associated routine

The routines will need to be able to read the files. Start there. If your code cannot open / read the file it cannot save it.

Do that one file type at a time. The syntax for the remaining file types will be almost identicle, the major difference will be naming conventions and locations.

Example: Open(bla, bla bla @ such and such) as HTML, or JPEG or Text.

More information about what you have accomplished would help us help you. Are you creating a GUI? Will it have menu options?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.