Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleUse the MSComm control to dial a phone number
Keywordsphone, modem, dial, dialer
CategoriesMultimedia
 
If the MSComm control is open, close it. Then set the port number and select 9600 baud, no parity, 8 data bits, 1 stop bit. You may need to change these parameters for your modem.

Open the port and send the attention string to your modem. Again, this string may be different for your modem.

Wait for an OK indicating the modem is ready. Then send the dial command.

 
Private Sub cmdDial_Click()
Const MAX_TRIES = 10000

Dim results As String
Dim num_tries As Long

    Screen.MousePointer = vbHourglass
    DoEvents
    On Error GoTo Oops

    ' Try to give MSComm1 time to close.
    If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
    DoEvents

    ' Set the comm port number.
    MSComm1.CommPort = CInt(cboCommPort.Text)

    ' Read the entire buffer when Input is used.
    MSComm1.InputLen = 0

    ' 9600 baud, no parity, 8 data bits, 1 stop bit.
    MSComm1.Settings = "9600,N,8,1"

    ' Open the comm port.
    MSComm1.PortOpen = True

    ' Send the attention string to the modem.
    MSComm1.Output = "ATV1Q0" & Chr$(13)

    ' Wait for OK.
    Do
        ' Read the latest data from the serial port.
        DoEvents
        results = results & MSComm1.Input
        num_tries = num_tries + 1
        If num_tries > MAX_TRIES Then
            MsgBox "Did not get OK response in " & _
                MAX_TRIES & " tries"
            Exit Do
        End If
    Loop Until InStr(results, "OK" & vbCrLf) > 0

    ' Dial the phone number.
    MSComm1.Output = "ATDT " & _
        CleanPhoneNumber(txtPhoneNumber.Text) & vbCr

    ' Ask the user to wait until the phone rings.
    MsgBox "When you hear a busy signal, click OK." & _
        vbCrLf & _
        "When you hear a ringing signal, pick up the " & _
            "receiver and click OK.", _
        vbInformation Or vbOKOnly, "Please Wait"

    ' Close the serial port.
    MSComm1.PortOpen = False
    Screen.MousePointer = vbDefault
    Exit Sub

Oops:
    MsgBox "Error " & Err.Number & vbCrLf & _
        Err.Description, _
        vbExclamation Or vbOKOnly, _
        "Error"
    Screen.MousePointer = vbDefault
    Exit Sub
End Sub
 
You can use this method to make a program that helps the user dial a number. For example, when the user clicks on a customer record's phone icon, the program could dial the number for the user. On a busy signal, the user would click OK to close the port. On a ring tone, the user would pick up the receiver and then click OK.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated