etGatherDigits Sample Program Source Code

Private Const MILLISECOND = 0.000000011574

Private Sub SetGatherDigits()
    If CheckActive.Value = Unchecked Then
        ' Stop gathering digits
        etLine1.CallGatherDigitsActive = False
    Else
        ' Clear the digit display
        TextDigits.Text = ""

        ' Begin to gather digits
        etLine1.CallGatherDigitsTimeOut = Val(TextTimeOut.Text)
        etLine1.CallGatherDigitsTerminate = TextTerminate.Text
        etLine1.CallGatherDigitsCount = Val(TextCount.Text)
        etLine1.CallGatherDigitsActive = True
    End If

    ' Update the Active check box
    If etLine1.CallGatherDigitsActive Then
        TextStatusetLine.Text = "Call.GatherDigits.Active = True"

        CheckActive.Value = Checked

        'Lock the following controls while gathering digits
        TextTimeOut.Locked = True
        TextTerminate.Locked = True
        TextCount.Locked = True
        TextDelay.Locked = True
    Else
        TextStatusetLine.Text = "Call.GatherDigits.Active = False"

        CheckActive.Value = Unchecked

        'Unlock the following controls while not gathering digits
        TextTimeOut.Locked = False
        TextTerminate.Locked = False
        TextCount.Locked = False
        TextDelay.Locked = False
    End If
    If Not etLine1.CallActive Then
        TextStatusetLine.Text = "OnIdle"
    End If
End Sub

Private Sub CheckActive_Click()
    SetGatherDigits
End Sub

Private Sub ComboDevice_Click()
    ' Set the TAPI Line device
    etLine1.DeviceName = ComboDevice.Text

    ' Check to see if the selected device supports gathering digits
    If ((etLine1.AddressCapabilitiesCallFeatures And _
         LINECALLFEATURE_GATHERDIGITS) = 0) Then
        MsgBox ("This device does not support Gathering Digits" & vbCrLf&vbCrLf &_
                "Use the etGatherDigitsWorkAround sample program.")
        ' Disable the Active check box
        CheckActive.Enabled = False
    Else
        'Active the line device
        etLine1.DeviceActive = True

        If etLine1.DeviceActive Then
            TextStatusetLine.Text = "OnIdle"
            ' Enable the Dial button
            CheckActive.Enabled = True
        Else
            TextStatusetLine.Text = "Device.Active = False"
            ' Disable the Active check box
            CheckActive.Enabled = False
        End If
    End If
End Sub

Private Sub etLine1_OnCallEnd(ByVal CallHandle As Long)
    TextStatusetLine.Text = "OnIdle"
End Sub

Private Sub etLine1_OnConnected(ByVal CallHandle As Long)
    TextStatusetLine.Text = "OnConnected"
    SetGatherDigits
End Sub

Private Sub etLine1_OnDigitsGathered(ByVal CallHandle As Long, _
                                     ByVal Digits As String, _
                                     ByVal Termination As Long, _
                                     ByVal Tag As Long)
    CheckActive.Value = Unchecked

    ' Display the gathered Digits
    TextDigits.Text = Digits

    ' Display the reason why digit gathering stopped
    Select Case Termination
        Case LINEGATHERTERM_BUFFERFULL
            TextStatusetLine.Text = "OnDigitsGathered - Buffer full"
        Case LINEGATHERTERM_TERMDIGIT
            TextStatusetLine.Text = "OnDigitsGathered - Terminating digit"
        Case LINEGATHERTERM_FIRSTTIMEOUT
            TextStatusetLine.Text = "OnDigitsGathered - Timeout"
        Case LINEGATHERTERM_INTERTIMEOUT
            TextStatusetLine.Text = "OnDigitsGathered - Timeout"
        Case LINEGATHERTERM_CANCEL
            TextStatusetLine.Text = "OnDigitsGathered - Canceled"
        Case Else
            TextStatusetLine.Text = "OnDigitsGathered - Unknown"
        End Select
End Sub

Private Sub etLine1_OnDisconnected(ByVal CallHandle As Long)
Dim dtStart

    TextStatusetLine.Text = "OnDisconnected"
    If etLine1.CallGatherDigitsActive Then
        ' if Gathering digits then stop
        etLine1.CallGatherDigitsActive = False

        ' Dialogic cards required a short delay after terminating the GatherDigits
        If Val(TextHangupDelay.Text) > 0 Then
            ' Store the current time
            dtStart = Now
            ' Loop for the number of milliseconds in TextHangupDelay.Text
            Do While Now < dtStart + (MILLISECOND * Val(TextHangupDelay.Text))
                ' Allow Windows messages to be processed
                DoEvents
            Loop
        End If
    End If
    etLine1.CallHangup
End Sub

Private Sub etLine1_OnError()
    If etLine1.ErrorNumber = TAPIREPLYTIMEOUT Then
        MsgBox (etLine1.ErrorText & vbCrLf & _
            "The program will terminate when you click OK" & vbCrLf & vbCrLf & _
            "Increase the Delay value and try again...")
        End
    End If
End Sub

Private Sub etLine1_OnOffering(ByVal CallHandle As Long)
    TextStatusetLine.Text = "OnOffering"
    TextDigits.Text = ""
    'Answer the call as soon as it is available
    etLine1.CallAnswer
End Sub

Private Sub Form_Load()
    'Enable the TeleTools etLine control
    etLine1.Enabled = True

    'Set the timeout to a lower value for testing
    etLine1.TAPIREPLYTIMEOUT = 15000

    ' Fill the device combo box and select the first device
    ComboDevice.Clear
    etLine1.DeviceID = 0
    For L = 0 To etLine1.DeviceCount - 1
        ComboDevice.AddItem etLine1.DeviceList(L)
    Next L
    If ComboDevice.ListCount > 0 Then
        ComboDevice.Text = ComboDevice.List(0)
    End If
End Sub