
How to dial a phone number with VB5
Hi Daniel.
Forgive all the text but I sent a section out of the Visual Basic 5.0 Books
on-line. It seems to suggest how to do what you want. But I haven't tried it.
-Dick Christoph
http://www1.minn.net/~dchristo
(From Books Online)
Figure 2.1 The Communications control
The Communications control provides an interface to a standard set of
communications commands. It allows you to establish a connection to a serial
port, connect to another communication device (a modem, for instance), issue
commands, exchange data, and monitor and respond to various events and errors
that may be encountered during a serial connection.
Possible Uses
Dial a phone number.
Monitor a serial port for incoming data.
Create a full-featured terminal program.
Sample Applications: Dialer.vbp and VBTerm.vbp
The Dialer.vbp and VBTerm.vbp sample applications, located in the Tools\Samples
directory of the Visual Basic CD-ROM, demonstrate simple and complex
(respectively) programming techniques of the Communications control.
Basics of Serial Communications
Every computer comes with one or more serial ports. They are named successively:
COM1, COM2, etc. On a standard PC, the mouse is usually connected to the COM1
port. A modem may be connected to COM2, a scanner to COM3, etc. Serial ports
provide a channel for the transmission of data from these external serial
devices.
The essential function of the serial port is to act as an interpreter between
the CPU and the serial device. As data is sent through the serial port from the
CPU, Byte values are converted to serial bits. When data is received, serial
bits are converted to Byte values.
A further layer of interpretation is needed to complete the transmission of
data. On the operating system side, Windows uses a communications driver,
Comm.drv, to send and receive data using standard Windows API functions. The
serial device manufacturer provides a driver that connects its hardware to
Windows. When you use the Communications control, you are issuing API functions,
which are then interpreted by Comm.drv and passed to the device driver.
As a programmer, you need only concern yourself with the Windows side of this
interaction. As a Visual Basic programmer, you need only concern yourself with
the interface that the Communications control provides to API functions of the
Windows communications driver. In other words, you set and monitor properties
and events of the Communications control.
Establishing the Serial Connection
The first step in using the Communications control is establishing the
connection to the serial port. The following table lists the properties that are
used to establish the serial connection:
Properties Description
CommPort Sets and returns the communications port number.
Settings Sets and returns the baud rate, parity, data bits, and stop bits as a
string.
PortOpen Sets and returns the state of a communications port. Also opens and
closes a port.
Opening the Serial Port
To open a serial port, use the CommPort, PortOpen, and Settings properties. For
example:
' Open the serial port
MSComm1.CommPort = 2
MSComm1.Settings = "9600,N,8,1"
MSComm1.PortOpen = True
The CommPort property sets which serial port to open. Assuming that a modem is
connected to COM2, the above example sets the value to 2 (COM2) and connects to
the modem. You can set the CommPort property value to any number between 1 and
16 (the default is 1). If, however, you set this value to a COM port that does
not exist for the system on which your application is run, an error will be
generated.
The Settings property allows you to specify the baud rate, parity, and the
number of data bits and stop bits. By default, the baud rate is set at 9600. The
parity setting is for data validation. It is commonly not used, and set to "N".
The data bits setting specifies the number of bits that represent a chunk of
data. The stop bit indicates when a chunk of data has been received.
Once youve specified which port to open and how data communication is to be
handled, you use the PortOpen property to establish the connection. It is a
Boolean value, True or False. If, however, the port is not functional, if the
CommPort property is set incorrectly, or if the device does not support the
settings youve specified, an error will be generated or the external device may
not work correctly. Setting the value of the PortOpen property to False closes
the port.
Working with a Modem
In most cases, you will use the Communications control to program your
application to work with a modem. With the Communications control, you can use
the standard Hayes-compatible command set to dial a phone number, or connect to
and interact with another modem.
Once the serial port connection has been established using the CommPort,
Settings, and PortOpen properties, you use the Output property to activate and
interact with the modem. The Output property is used to issue commands which
control the interaction between one modem and another. For example:
' Activate the modem and dial a phone number.
MSComm1.Output = "ATDT 555-5555" & vbCr
In the example above, the command "AT" initiates the connection, "D" dials the
number, and "T" specifies touch tone (rather than pulse). A carriage return
character (vbCr) must be specified when an AT command is used.
When a command is successfully processed, an "OK" result code will be returned.
You can test for this result code to determine if a command was processed
successfully.
For More Information For a complete list of Hayes-compatible commands, check
your modem documentation.
Quote:
> Good day to all, I am desperatly trying to dial a phone number thru code but
> it does not work.
> Her is below my code for the cmdDial_click event
> PhoneNumber$ = txtNumero.Text
> If optPort1.Value = True Then
> Open "COM1" For Output As #1
> Print #1, "ATDT" & PhoneNumber$ & Chr$(13)
> Close #1
> End If
> If optPort2.Value = True Then
> Open "COM2" For Output As #1
> Print #1, "ATDT" & PhoneNumber$ & Chr$(13)
> Close #1
> End If
> If optPort3.Value = True Then
> Open "COM3" For Output As #1
> Print #1, "ATDT" & PhoneNumber$ & Chr$(13)
> Close #1
> End If
> If optPort4.Value = True Then
> Open "COM4" For Output As #1
> Print #1, "ATDT" & PhoneNumber$ & Chr$(13)
> Close #1
> End If
> Theorically, it should work easily as it did in VB4-32 but in VB5????????
> Not at all
> Am I missing something ??
> Daniel Caron
> Thetford Mines,Qc,Canada