Link to home
Start Free TrialLog in
Avatar of John Malalis
John MalalisFlag for Philippines

asked on

MSComm Dialer REturn Ring

Hi, I have a vb6 code copy from google which dial a phone via MSComm. Based on the code, I need to know if the number I dialed is ringing or not. I attached here the entire codes, hoping that someone helps me done my project. Thank you

Option Explicit
' Clean the phone number, remove extraneous characters
' like - and (, and convert letters into digits.
Private Function CleanPhoneNumber(ByVal phone_number As String) As String
Dim result As String
Dim i As Integer

    For i = 1 To Len(phone_number)
        result = result & PhoneDigit(Mid$(phone_number, i, 1))
    Next i

    CleanPhoneNumber = result
End Function

' If "letter" is number, return it unchanged.
' If "letter" is a letter, return the corresponding
' telephone digit.
' If "letter" is something else, return "".
Private Function PhoneDigit(ByVal letter As String) As String
    letter = UCase(letter)

    If letter >= "0" And letter <= "9" Then
        PhoneDigit = letter
    ElseIf letter >= "A" And letter <= "Z" Then
        Select Case letter
            Case "A" To "C"
                PhoneDigit = 2
            Case "D" To "F"
                PhoneDigit = 3
            Case "G" To "I"
                PhoneDigit = 4
            Case "J" To "L"
                PhoneDigit = 5
            Case "M" To "O"
                PhoneDigit = 6
            Case "P" To "S"
                PhoneDigit = 7
            Case "T" To "V"
                PhoneDigit = 8
            Case "W" To "Z"
                PhoneDigit = 9
        End Select
        PhoneDigit = ""
    End If
End Function

Private Sub cmdDial_Click()
Const MAX_TRIES = 10000

Dim results As String
Dim num_tries As Long

    Screen.MousePointer = vbHourglass
    On Error GoTo Oops

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

    ' 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.
        ' Read the latest data from the serial port.
        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

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

    MsgBox "Error " & Err.Number & vbCrLf & _
        Err.Description, _
        vbExclamation Or vbOKOnly, _
    Screen.MousePointer = vbDefault
    Exit Sub
End Sub

Private Sub Form_Load()
    cboCommPort.Text = 11
End Sub

Open in new window

Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

your modem has to first support returning that string. and you have to enable it  via the verbose settings i.e. ATX4 see your modem's manual to see what it supports..

Typical AT command set
Avatar of John Malalis


Hello David, I may first need to correct the code below before going further. Please understand that I am new beginner of vb6 coding. My purpose is to know if the dialed number is existing or not. I found that there's a message return from the modem like "NO CARRIER" and "NO ANSWER". I wish to use them and make some actions once I received that kind of  reply. I inserted the code after dialing the phone. I could not catch the message when I use debug. So I don't know how to correct the code. Please, I need some  guide.. Thank you.

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

       dummy = DoEvents()
       '-- If there is data in the buffer, then read it.
       If MSComm1.InBufferCount Then
          FromModem = FromModem + MSComm1.Input
          '-- Check if the message is "NO CARRIER"
          If InStr(FromModem$, "NO CARRIER") Then
             Exit Do
             ' put in some redial code here
          End If
       End If

Open in new window

use a terminal and connect to the modem. With my BBS experience  I don't remember ever seeing a ringing response from the modem.. just no dial tone and busy
Hello David. How do I know if the call is answered? 
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial