Solved

Transfer data via modem

Posted on 2003-11-17
7
981 Views
Last Modified: 2013-11-13
Hi
I 'm VB programmer and my programm send text file to another PC with mscomm32 in VB
but I want send and receive any type of data (*.exe or *.avi or *.bmp, etc) and I don't know how
can open any type of file and read it and send data and another Pc receive this file and save it .
I open file binary but it can only read text file.i use this code.
please tell me how can open and read file and save it
goodluck

open namefile for binary access read  as #filenum
input #filenum,variable
mscomm1.output=variable

or

open file name for input  as #filenum
input #filenum,variable
mscomm1.output=variable

0
Comment
Question by:mashal
  • 3
  • 2
  • 2
7 Comments
 
LVL 3

Expert Comment

by:NBrownoh
ID: 9762751
winsock will be the best solution, if you want to see an example let me know, ill throw one up on my webserver for you.
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 25 total points
ID: 9765763
Don't use input #filenum, variable to read files in binary mode.

Use the Get() function

dim variable as string
variable = space(4096) ' read file in 4096 byte chunks
open namefile for binary access read  as #filenum
get #filenum,,variable
mscomm1.output=variable ' use winsock instead like NBrownoh suggested!

Of course, if the file is smaller that 4096 bytes then just read the whole thing.  If it is larger, then you have to to determine if their will be a smaller chunk remaining at the end to send.

Idle_Mind
0
 

Author Comment

by:mashal
ID: 9770321
I have a problem with mscomm32 because my buffer size is 1024 byte and my data that will be send is larger than output buffer how can receive this data in another PC ( mscomm.input) i must use array ?
please help me . my buffer is small and data is large and how can save data in another pc
thanks
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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 85

Expert Comment

by:Mike Tomlinson
ID: 9771023
Can you use Winsock on both sides?
0
 

Author Comment

by:mashal
ID: 9771114
hi Idle_Mind
I can't use winsock and I want open and read any size of file for reading and writing operation.
0
 
LVL 3

Expert Comment

by:NBrownoh
ID: 9773159
can you network to that PC?  winsock is really the only way to transfer data over a modem/nic
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 9773515
' Sending the file...
Private Sub sendFile(fileName As String)
    Dim ff As Integer
    Dim fileSize As Long
    Dim data() As Variant
   
    If Dir(fileName) = "" Then
        MsgBox fileName & " does not exist."
        Exit Sub
    End If
   
    ff = FreeFile
    Open fileName For Input As #ff
    fileSize = LOF(ff)
    While fileSize
        If fileSize > 1024 Then
            data = Input(1024, ff)
            fileSize = fileSize - 1024
        Else
            data = Input(fileSize, ff)
            fileSize = 0
        End If
        MSComm1.Output data

        While MSComm1.OutBufferCount
            DoEvents
        Wend
    Wend
    Close #ff
End Sub
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The viewer will learn how to implement Singleton Design Pattern in Java.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

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