troubleshooting Question

VB query modem for Dial Tone

Avatar of BigBobBK
BigBobBK asked on
Visual Basic Classic.NET Programming
4 Comments1 Solution950 ViewsLast Modified:
I'm trying to use VB to detect a dial tone from my USRobotics 56K modem on serial port 1.  I've created this script and it works when I step thru it in debug but when I try to run the script it never reports a No Dialtone message.

I've been fighting this for days.  Can someone please help me?  Here is what I have:
--------------------------------------------------------------------------
Private Sub Command1_Click()
Dial (Number)
Unload Me
End
End Sub

Private Sub Form_Load()

'Option Explicit
Dim PhoneNumbers() As String
Dim CancelFlag
End Sub

Private Sub CancelButton_Click()
    CancelFlag = True

    CancelButton.Enabled = False
End Sub

Private Sub Dial(Number)
    Dim DialString As String, FromModem As String
    Dim StopString As String
    Dim Delay As Double
    Dim sData As String

    DialString = "ATX4&D2DT" & sData & ";" & vbCr
   
    StopString = "ATH0" & vbCr
    '-- Comm port settings
    MSComm1.Settings = "9600,N,8,1"
   
    '-- Open the comm port
    On Error Resume Next
    MSComm1.PortOpen = True
    If Err Then
       MsgBox "COM1: not available. Change the CommPort property to another port."
       Exit Sub
    End If
   
    '-- Flush the input buffer
    MSComm1.InBufferCount = 0
   
    '-- Dial the number
    MSComm1.Output = DialString
   
    '-- Wait for "OK" to come back from the modem
    Dim cnt As Integer
   
    Do
       DoEvents
       '-- If there is data in the buffer, then read it.



       If MSComm1.InBufferCount Then
              Dim x As Integer
       x = x + 1
       
        If x > "5" Then
          FromModem = FromModem & MSComm1.Input
          '-- Check for "OK"
          If InStr(FromModem, "OK") Then
             '-- Notify the user to pick up the phone
             FromModem = ""
             Beep
             MsgBox "Please pick up the phone and either press Enter, or click OK"
             Exit Do
          ElseIf InStr(FromModem, "NO DIAL TONE") Or InStr(FromModem, "NO DIALTONE") Then
             FromModem = ""
             Beep
             MsgBox "Dialtone not detected.  Please check the telephone connection."
             CancelFlag = True
             Exit Do
          End If
       End If
       End If
       
       '-- Was Cancel pressed?
       If CancelFlag Then
          CancelFlag = False
          Exit Do
       End If
    Loop

    '-- Disconnect the modem
    Comm1.Output = StopString
   
    '-- Close the port
    Delay = Timer
    While Delay + 1 > Timer
        DoEvents
       '-- If there is data in the buffer, then read it.
       If Comm1.InBufferCount Then
          FromModem = FromModem & Comm1.Input
       End If
    Wend
    Comm1.DTREnable = False    'belts and suspenders
    Delay = Timer              'disconnect.  If StopString
    While Delay + 1 > Timer    'worked, this isn't needed.
        DoEvents
    Wend
    Comm1.DTREnable = True
    Comm1.PortOpen = False
End Sub
ASKER CERTIFIED SOLUTION
Karen
Analyst programmer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros