|
|
etIVR4Line Sample Program Source Code
Const TAG_MENU = 0
Const TAG_WAVEPLAY = 1
Const TAG_RECORDING = 2
Const TAG_ENDCALL = 99
Dim gsPath As String
Dim gsMenu As String
Private Sub DisplayLineError(Error As String, Index As Integer)
If etLine(Index).ErrorNumber <> 0 Then
MsgBox ("Error " + sError + vbCrLf + _
"etLine.DeviceID" + vbTab + vbTab + " = " +
_
Str(etLine(Index).DeviceID) + vbCrLf + _
"etLine.DeviceName" + vbTab + vbTab + " = " + _
etLine(Index).DeviceName + vbCrLf + _
"etLine.ErrorHex" + vbTab + vbTab + " = " + _
etLine(Index).ErrorHex + vbCrLf + _
"etLine.ErrorNumber" + vbTab + vbTab + " = " +
_
Str(etLine(Index).ErrorNumber) + vbCrLf + _
"etLine.ErrorText" + vbTab + vbTab + " = " + _
etLine(Index).ErrorText)
End If
End Sub
Private Sub DisplayPlayError(Error As String, Index As Integer)
If etPlay(Index).ErrorNumber <> 0 Then
If (sError = "setting play device") Then
MsgBox ("Error " + sError + vbCrLf + _
"etPlay.DeviceID" + vbTab + vbTab + " = " +
_
Str(etPlay(Index).DeviceID) + vbCrLf + _
"etPlay.DeviceName" + vbTab + vbTab + " = " + _
etPlay(Index).DeviceName + vbCrLf + _
"etPlay.ErrorHex" + vbTab + vbTab + " = " + _
etPlay(Index).ErrorHex + vbCrLf + _
"etPlay.ErrorNumber" + vbTab + vbTab + " = " + _
Str(etPlay(Index).ErrorNumber) + vbCrLf + _
"etPlay.ErrorText" + vbTab + vbTab + " = " + _
etPlay(Index).ErrorText)
Else
MsgBox ("Error " + sError + vbCrLf + _
"etPlay.FileName " + vbTab + vbTab + " = " + _
etPlay(Index).SourceFileName + vbCrLf + _
"etPlay.DeviceID" + vbTab + vbTab + " = " + _
Str(etPlay(Index).DeviceID) + vbCrLf + _
"etPlay.DeviceName" + vbTab + vbTab + " = " +
_
etPlay(Index).DeviceName + vbCrLf + _
"etPlay.ErrorHex" + vbTab + vbTab + " = " + _
etPlay(Index).ErrorHex + vbCrLf + _
"etPlay.ErrorNumber" + vbTab + vbTab + " = " + _
Str(etPlay(Index).ErrorNumber) + vbCrLf + _
"etPlay.ErrorText" + vbTab + vbTab + " = " + _
etPlay(Index).ErrorText)
End If
End If
End Sub
Private Sub DisplayRecordError(Error As String, Index As Integer)
If etRecord(Index).ErrorNumber <> 0 Then
If (sError = "setting record device") Then
MsgBox ("Error " + sError + vbCrLf + _
"etRecord.DeviceID" + vbTab + vbTab + " = " +
_
Str(etRecord(Index).DeviceID) + vbCrLf + _
"etRecord.DeviceName" + vbTab + vbTab + " = " +
_
etRecord(Index).DeviceName + vbCrLf + _
"etRecord.ErrorHex" + vbTab + vbTab + " = " +
_
etRecord(Index).ErrorHex + vbCrLf + _
"etRecord.ErrorNumber" + vbTab + vbTab + " = " +
_
Str(etRecord(Index).ErrorNumber) + vbCrLf + _
"etRecord.ErrorText" + vbTab + vbTab + " = " +
_
etRecord(Index).ErrorText)
Else
MsgBox ("Error " + sError + vbCrLf + _
"etRecord.FileName " + vbTab + vbTab + " = " +
_
etRecord(Index).SourceFileName + vbCrLf + _
"etRecord.DeviceID" + vbTab + vbTab + " = " +
_
Str(etRecord(Index).DeviceID) + vbCrLf + _
"etRecord.DeviceName" + vbTab + vbTab + " = " +
_
etRecord(Index).DeviceName + vbCrLf + _
"etRecord.ErrorHex" + vbTab + vbTab + " = " +
_
etRecord(Index).ErrorHex + vbCrLf + _
"etRecord.ErrorNumber" + vbTab + vbTab + " = " +
_
Str(etRecord(Index).ErrorNumber) + vbCrLf + _
"etRecord.ErrorText" + vbTab + vbTab + " = " +
_
etRecord(Index).ErrorText)
End If
End If
End Sub
Private Sub SetLineDevice(Index As Integer, Device As Integer)
If etLine(Index).DeviceActive Then
'If the device is currently active then it should first be closed
etLine(Index).DeviceActive = False
If etLine(Index).ErrorNumber <> 0 Then
Call DisplayLineError("closing line device", Index)
Exit Sub
End If
CheckActive(Index).Value = Unchecked
End If
'Set the etLine control to use the given TAPI Line device
etLine(Index).DeviceID = Device
ComboDevice(Index).ListIndex = etLine(Index).DeviceID
Call DisplayLineError("setting line device", Index)
End Sub
Private Sub SetPlayRecordDevices(Index As Integer)
'Check to see if the TAPI Line device has a Wave Play device
If Not etLine(Index).WavePlayAvailable Then
If etLine(Index).DeviceActive Then
LabelPlayDevice(Index).Caption = "<Not available>"
Else
LabelPlayDevice(Index).Caption = "<Line device is inactive>"
End If
Else
'Set the etPlay control to use the correct wave device
etPlay(Index).DeviceID = etLine(Index).WavePlayID
LabelPlayDevice(Index).Caption = etPlay(Index).DeviceName
End If
If Not etLine(Index).WaveRecordAvailable Then
If etLine(Index).DeviceActive Then
LabelRecordDevice(Index).Caption = "<Not available>"
Else
LabelRecordDevice(Index).Caption = "<Line device is inactive>"
End If
Else
'Set the etPlay control to use the correct wave device
etRecord(Index).DeviceID = etLine(Index).WaveRecordID
LabelRecordDevice(Index).Caption = etRecord(Index).DeviceName
'This will cause 1/4 of a second to be trimed from the recordings
'keeping the DTMF tone from being recorded.
etRecord(Index).DeviceTrim = 250
End If
End Sub
Private Sub CheckActive_Click(Index As Integer)
'If etLine is currently active then deactivate it
If CheckActive(Index).Value = Unchecked Then
'If a wave file is currently playing then stop it
If etPlay(Index).DeviceActive Then
etPlay(Index).DeviceActive = False
End If
'If a wave file is currently recording then stop it
If etRecord(Index).DeviceActive Then
etRecord(Index).DeviceActive = False
End If
'If a call is currently connected then hang up
If etLine(Index).CallActive Then
etLine(Index).CallActive = False
End If
'Deactivate the line device
etLine(Index).DeviceActive = False
If etLine(Index).ErrorNumber <> 0 Then
Call DisplayLineError("deactivating line device", Index)
End If
Else
'Activate the line device
etLine(Index).DeviceActive = True
If etLine(Index).ErrorNumber = INVALID_SERIAL_NUMBER Then
MsgBox ("Error opening line device: " & etLine(Index).ErrorText &
_
vbCrLf & vbCrLf & "See the help topic:" & vbCrLf & vbCrLf & _
vbTab & "Why Serial Numbers Are Important")
End If
If (etLine(Index).ErrorNumber = LINEERR_INVALMEDIAMODE) Then
MsgBox ("TeleTools has detected that your device is a (" &
_
etLine(Index).DeviceName & ") DATA modem and therefore has
"&_
"no voice capabilities." & vbCrLf & vbCrLf & "This device
" &_
"will be able to:" & vbCrLf & vbCrLf & vbTab & "DIAL" &
_
vbCrLf & vbCrLf & "If you think you have a voice modem,
" & _
"expected more functionality, or other programs provide " &
_
"more functionality with this modem, see the topic 'Working"&_
" with Modems' in the Appendix of the TeleTools help file.")
End If
'Time for a little error checking
Call DisplayLineError("activating line device", Index)
End If
'Set the Play devices
Call SetPlayRecordDevices(Index)
If etLine(Index).DeviceActive Then
CheckActive(Index).Value = Checked
LabelLineStatus(Index).Caption = "etLine.DeviceActive = True"
' Not all telephony devices are capable of controling the volume
' of the wave play device. This includes modems that use the
' Microsoft UnimodemV telephony service provider. The following
' code checks to see if the Unimodem TSP is being used and
' disables etPlay from working with the volume properties.
If InStr(1, etLine(Index).TAPITSP, "Modem", 1) > 0 Then
etPlay(Index).VolumeEnabled = False
Else
etPlay(Index).VolumeEnabled = True
End If
Else
CheckActive(Index).Value = Unchecked
LabelLineStatus(Index).Caption = "etLine.DeviceActive = False"
End If
End Sub
Private Sub ComboDevice_Click(Index As Integer)
Call SetLineDevice(Index, ComboDevice(Index).ListIndex)
CheckActive(Index).Value = Unchecked
End Sub
Private Sub CommandTeleScopes_Click(Index As Integer)
Dim bTemp As Boolean
bTemp = etLine(Index).TeleScopeVisible
etLine(Index).TeleScopeVisible = Not etLine(Index).TeleScopeVisible
If etLine(Index).ErrorNumber <> 0 Then
If bTemp Then
Call DisplayLineError("etLine.TeleScopeVisible = True", Index)
Else
Call DisplayLineError("etLine.TeleScopeVisible = False", Index)
End If
End If
etPlay(Index).TeleScopeVisible = etLine(Index).TeleScopeVisible
If etPlay(Index).ErrorNumber <> 0 Then
If bTemp Then
Call DisplayPlayError("etPlay.TeleScopeVisible = True", Index)
Else
Call DisplayPlayError("etPlay.TeleScopeVisible = False", Index)
End If
End If
etRecord(Index).TeleScopeVisible = etLine(Index).TeleScopeVisible
If etRecord(Index).ErrorNumber <> 0 Then
If bTemp Then
Call DisplayRecordError("etRecord.TeleScopeVisible = True", Index)
Else
Call DisplayRecordError("etRecord.TeleScopeVisible = False", Index)
End If
End If
End Sub
Private Sub etLine_OnConnected(Index As Integer, ByVal CallHandle As Long)
LabelLineStatus(Index).Caption = "etLine.OnConnected"
etLine(Index).CallMonitorDigitsActive = True 'Start capturing digits!
'Play the greeting
etPlay(Index).SourceFileName = gsPath + "IVRGreet"
etPlay(Index).DeviceLoop = False
etPlay(Index).DeviceActive = True
If etPlay(Index).ErrorNumber <> 0 Then
Call DisplayPlayError("playing file", Index)
etLine(Index).CallHangup 'Hangup because of an error
If etLine(Index).ErrorNumber <> 0 Then
Call DisplayLineError("hanging up", Index)
End If
End If
End Sub
Private Sub etLine_OnDigitReceived(Index As Integer, ByVal CallHandle As Long, ByVal Digit As Integer, ByVal Tag As Long)
Dim sTemp As String
Dim X As Integer
LabelLineStatus(Index).Caption = "etLine.OnDigitReceived [" + Chr(Digit) + "]"
etPlay(Index).DeviceActive = False
If etPlay(Index).ErrorNumber <> 0 Then
Call DisplayPlayError("stopping file", Index)
etLine(Index).CallHangup 'Hangup because of an error
If etLine(Index).Error.Number <> 0 Then
Call DisplayLineError("hanging up", Index)
End If
Exit Sub
End If
etPlay(Index).DeviceLoop = False
Select Case Tag
Case TAG_RECORDING
LabelLineStatus(Index).Caption = "etRecord.DeviceActive = False"
etRecord(Index).DeviceActive = False
If etRecord(Index).ErrorNumber <> 0 Then
Call DisplayRecordError("Stoping recording", Index)
etPlay(Index).SourceFileName = gsMenu
etPlay(Index).DeviceLoop = True
Else
etPlay(Index).SourceFileName = etRecord(Index).SourceFileName
etPlay(Index).DeviceLoop = False
End If
etLine(Index).CallTag = TAG_WAVEPLAY
Case TAG_MENU
Select Case Chr(Digit)
Case "1"
If (etLine(Index).CallCallerIDFlags And _
LINECALLPARTYID_ADDRESS) = 0 Then
etPlay(Index).SourceFileName = gsPath + "NoCallerID"
Else
etPlay(Index).SourceFileName = gsPath + "CalledFrom"
sTemp = etLine(Index).CallCallerIDNumber
For X = 1 To Len(sTemp)
If (Mid(sTemp, X, 1) >= "0") And _
(Mid(sTemp, X, 1) <= "9") Then
etPlay(Index).SourceFileName = _
etPlay(Index).SourceFileName + "," + _
Mid(sTemp, X, 1)
End If
Next X
End If
etLine(Index).CallTag = TAG_WAVEPLAY
Case "2"
etPlay(Index).SourceFileName = gsPath + "MenuOpt2"
etLine(Index).CallTag = TAG_WAVEPLAY
Case "3"
etPlay(Index).SourceFileName = gsPath + "MenuOpt3"
etLine(Index).CallTag = TAG_WAVEPLAY
Case "4"
etPlay(Index).SourceFileName = gsPath + "MenuOpt4"
etLine(Index).CallTag = TAG_WAVEPLAY
Case "5"
'Not all telephony devices are capable of recording with the
'format PCM 8,000 hz, 16 bit, Mono. For example if you are
'using a Dialogic card you will need to use the following line
'of code to select a different format.
If InStr(1, etLine(Index).TAPITSP, "Dialogic", 1) > 0 Then
etRecord(Index).SourceFormatID = wfuLaw08000M08
Else
etRecord(Index).SourceFormatID = wfPCM08000M16
End If
etRecord(Index).SourceFileName = gsPath + "RecordLine" +
Str(etLine(Index).DeviceID) + ".wav"
LabelLineStatus(Index).Caption = _
"etRecord.DeviceActive = True"
etRecord(Index).DeviceActive = True
If etRecord(Index).ErrorNumber <> 0 Then
Call DisplayRecordError("Recording", Index)
End If
etLine(Index).CallTag = TAG_RECORDING
Case "#"
LabelLineStatus(Index).Caption = "etLine.Call.Hangup"
etRecord(Index).DeviceActive = False
If etRecord(Index).ErrorNumber <> 0 Then
Call DisplayRecordError("stopping recording", Index)
End If
etPlay(Index).DeviceActive = False
If etPlay(Index).ErrorNumber <> 0 Then
Call DisplayPlayError("stopping file", Index)
End If
etLine(Index).CallHangup
If etLine(Index).ErrorNumber <> 0 Then
Call DisplayLineError("hanging up", Index)
End If
etLine(Index).CallTag = TAG_ENDCALL
Exit Sub
Case Else
etPlay(Index).SourceFileName = gsMenu
etPlay(Index).DeviceLoop = True
etLine(Index).CallTag = TAG_MENU
End Select
Case Else
etPlay(Index).SourceFileName = gsMenu
etPlay(Index).DeviceLoop = True
etLine(Index).CallTag = TAG_MENU
End Select
If (etLine(Index).CallTag=TAG_MENU)Or(etLine(Index).CallTag=TAG_WAVEPLAY) Then
LabelLineStatus(Index).Caption = "etPlay.DeviceActive = True"
etPlay(Index).DeviceActive = True
If etPlay(Index).ErrorNumber <> 0 Then
Call DisplayPlayError("playing file", Index)
etLine(Index).CallHangup 'Hangup because of an error
If etLine(Index).ErrorNumber <> 0 Then
Call DisplayLineError("hanging up", Index)
End If
End If
End If
End Sub
Private Sub etLine_OnDisconnected(Index As Integer, ByVal CallHandle As Long)
LabelLineStatus(Index).Caption = "etLine.OnDisconnected"
etPlay(Index).DeviceActive = False
If etPlay(Index).ErrorNumber <> 0 Then
Call DisplayPlayError("stoping file", Index)
End If
If etLine(Index).CallState <> LINECALLSTATE_IDLE Then
etLine(Index).CallHangup
End If
If etLine(Index).ErrorNumber <> 0 Then
Call DisplayLineError("hanging up", Index)
End If
End Sub
Private Sub etLine_OnRing(Index As Integer,
_
ByVal Count As Long, _
ByVal RingMode As Long)
LabelLineStatus(Index).Caption = "etLine.OnRing [" + Str(Count) + "]"
'Wait until the ring count is 2 or the CallerID number becomes available
If (Count >= 2) Or _
((etLine(Index).CallCallerIDFlags And LINECALLPARTYID_ADDRESS) <> 0) Then
If Not etLine(Index).CallAnswer() Then
Call DisplayLineError("answering", Index)
End If
End If
End Sub
Private Sub etPlay_OnDone(Index As Integer)
LabelLineStatus(Index).Caption = "etPlay.OnDone"
If (etLine(Index).CallState = LINECALLSTATE_CONNECTED) And
_
(Not etPlay(Index).DeviceLoop) Then
etLine(Index).CallTag = TAG_MENU
etPlay(Index).SourceFileName = gsMenu
etPlay(Index).DeviceLoop = True
etPlay(Index).DeviceActive = True
If etPlay(Index).ErrorNumber <> 0 Then
Call DisplayPlayError("playing file", Index)
etLine(Index).CallHangup 'Hangup because of an error
If Controls.etLine.Error.Number <> 0 Then
Call DisplayLineError("hanging up", Index)
End If
End If
End If
End Sub
Private Sub Form_Load()
Dim X As Integer
Width = 6315
'Enabled all ExceleTel TeleTools controls before using them
etLine(0).Enabled = True
etPlay(0).Enabled = True
etRecord(0).Enabled = True
etLine(1).Enabled = True
etPlay(1).Enabled = True
etRecord(1).Enabled = True
etLine(2).Enabled = True
etPlay(2).Enabled = True
etRecord(2).Enabled = True
etLine(3).Enabled = True
etPlay(3).Enabled = True
etRecord(3).Enabled = True
gsPath = App.Path & "\"
gsMenu = gsPath & "Menu1,1,Menu2,2,Menu3,3,Menu4,4,Press,5,Record,EndCall"
For X = 0 To 3
ComboDevice(X).Clear
Next X
'Fill in the list boxes with all available telephony devices
etLine(0).DeviceID = 0
For X = 0 To etLine(0).DeviceCount - 1
ComboDevice(0).AddItem etLine(0).DeviceList(X)
ComboDevice(1).AddItem etLine(0).DeviceList(X)
ComboDevice(2).AddItem etLine(0).DeviceList(X)
ComboDevice(3).AddItem etLine(0).DeviceList(X)
Next X
For X = 0 To 3
If etLine(X).DeviceCount > X Then
Call SetLineDevice(X, X) ' Select the Line devices
Call SetPlayRecordDevices(X) 'Set the Play devices
End If
LabelLineStatus(X).Caption = ""
Next X
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim X As Integer
'Do a little clean up before closing the form and destroying the controls
For X = 0 To 3
If etLine(X).DeviceActive Then
etRecord(X).DeviceActive = False 'Stop recording wave file
etPlay(X).DeviceActive = False 'Stop playing wave file
etLine(X).CallHangup 'Hang up
etLine(X).DeviceActive = False 'Deactivate line device
End If
Next X
End Sub
|