Avatar of John Malalis
John Malalis
Flag 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
    Else
        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
    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



    ' 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

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



Open in new window

Visual Basic Classic* vb6

Avatar of undefined
Last Comment
David Johnson, CD

8/22/2022 - Mon
David Johnson, CD

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 https://michaelgellis.tripod.com/modem.html
John Malalis

ASKER
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  

Do
       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
             Beep
             Exit Do
             ' put in some redial code here
             Else
            
          End If
       End If
       
    Loop  

Open in new window

David Johnson, CD

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
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
John Malalis

ASKER
Hello David. How do I know if the call is answered? 
ASKER CERTIFIED SOLUTION
David Johnson, CD

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question