VB 6.0 - Using Tapi in Vbscript for dialing - Asked By TAPI Programmer on 01-Dec-08 04:30 AM

Hi All...

I'm very much new VBscript & TAPI.I'm writing a VBScript to dial a number through a modem attached to my PC.My problem is that script is dialing even if the number is in use instead of waiting or exiting..
I want to know..

1)How to check whether the telephone line attached to the modem is busy or not.
2)The status of the call generated (Ringing,busy,picked etc)
Here is my code...Please correct me if anything is wrong...
lAddressType = LINEADDRESSTYPE_PHONENUMBER
Set objTapi = CreateObject("TAPI.TAPI.1")
Set mapper = CreateObject("DispatchMapper.DispatchMapper.1")
objTapi.Initialize
objTapi.EventFilter = TAPI3_ALL_TAPI_EVENTS
Set objCollAddresses  = objTapi.Addresses
For lLoop = 1 To objCollAddresses.Count
Set objCrtAddress = objCollAddresses.Item(lLoop) 
            If (objCrtAddress.AddressName = "Motorola SM56 Speakerphone Modem"  )Then
             Set gobjAddress = objCrtAddress
             Exit For   
            End If       
Next

Set  TestCall = gobjAddress.CreateCall("97324586", lAddressType,LINEMEDIAMODE_INTERACTIVEVOICE)' lMediaTypes)'Set
TestCall.connect(False)

Thanks in advance...

Re :: Using TAPI in VBScript for Dialing - SP replied to TAPI Programmer on 01-Dec-08 04:40 AM

See the following articles ::

http://www.codeguru.com/forum/printthread.php?t=119608

http://www.vbforums.com/showthread.php?t=398578

Hope this helps.

TRY THIS COMPLETE SOURCE CODE FOR QUICKDIAL SAMPLE PROGRAM - C_A P replied to TAPI Programmer on 01-Dec-08 04:50 AM

etQuickDial Sample Program Source Code in VB

   For sourcecode in Delphi click http://www.exceletel.com/products/TeleTools/SamplePrograms/etQuickDial/SourceCodeDelphi.htm

 NOTE: You only need the events in your program that are important for your application. We show many event
             handlers here to show what kind of information you can view about a call and places you can put your code.
             Your own program will be even simpler.  For example, all of the event handlers below that simply log 
             information to the textbox could be replaced with this:

Private Sub etLine1_OnLog(ByVal Line As String)
  Text2.Text = Text2.Text & etLine1.CallHandle & vbCrLf & _
          etLine1.StringLINECALLSTATE(etLine1.CallState) & vbCrLf & _
          etLine1.StringLINECALLSTATEMODE(etLine1.CallState, _ 
          etLine1.CallStateMode)  &   vbCrLf
End Sub

            You could also use the etLine1_OnCallState event.  In any case, here is the sourcecode for the entire 
            etQuickDial TAPI sample program:


' *******************************************************************
' To make this program compile on your machine, be sure to have
' the etLine component on your form and to click the "AboutLoadSerialnumber"
' property to install your serial number into the component. Then click on
' the enabled property to set it to true. You must compile this program with
' a purchased serial number or it will operate with reminder screens.
'
' We recommend that for learning, testing and debugging, you turn the "visible"
' property of the etLine component to TRUE. You will then be able to click on
' the component at any time and launch TeleScope which will be your view into
' everything going on in your program. Please read the help file sections about
' TeleScope, it may be the most valuable first advice we can provide to you.
' You may also place the line, "etLine1.TeleScopeActive = True" anywhere in your
' code where you want TeleScope to popup. It's a great idea to include a secret
' hotkey combination in your code to enable the TeleScope for your components so
' that you or your clients can email informative logs.
'
' Thank You, and remember to contact us for any assistance you may require.
'
' Copyright © 2003
' ExceleTel, Inc
' Raleigh, NC
' 919-233-2232
' www.exceletel.com
'
' ******************************************************************

Private Sub Form_Load()
  'Enable all ExceleTel TeleTools controls before using them
  etLine1.Enabled = True
  ' etPhone1.Enabled = True (if you were using these...)
  ' etPlay1.Enabled = True
  ' etRecord1.Enabled = True

  ' Uses the etLine DeviceIdleDelay property to delay the OnIdle event from firing
  ' for 2 seconds. This gives devices such as modems and Dialogic cards that need
  ' time to reset between calls. Comment this line out and try quickly dialing and
  ' hanging up calls and see if you get RESOURCE_UNAVAILABLE or other errors.

  etLine1.DeviceIdleDelay = 2000

  ComboDevice.Clear
  etLine1.DeviceID = 0 ' clear device box and use devicelist to fill the list with TAPI devices
  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
  ComboDevice.ListIndex = GetSetting("READIAL", "TAPI Devie", "Line", 0)
End Sub

'****************************************************************
' CheckActive_Click - Activate and Deactivate the TAPI Line device
'****************************************************************
Private Sub CheckActive_Click()
  If CheckActive.Value = 0 Then
      If etLine1.DeviceActive Then
      WriteLog ("etLine1.DeviceActive = False")
      etLine1.DeviceActive = False
      If Not etLine1.DeviceActive Then
          CommandDial.Enabled = False
      Else
          WriteLog (vbTab & "Error = " & etLine1.ErrorText)
          CheckActive.Value = 1
      End If
  End If
  Else
      If Not etLine1.DeviceActive Then
          CommandHangup.Enabled = False
          WriteLog ("etLine.DeviceActive = True")
          etLine1.DeviceActive = True
          If etLine1.ErrorNumber = INVALID_SERIAL_NUMBER Then
              MsgBox ("Error opening line device: " & etLine1.ErrorText & vbCrLf & vbCrLf & _
              "See the help topic:" & vbCrLf & vbCrLf & _
              vbTab & "Why Serial Numbers Are Important")
          End If
          ' Check for invalid_mediamode error and check tsp property for a non compliant modem
          If (Not etLine1.DeviceActive) And (etLine1.ErrorNumber = LINEERR_INVALMEDIAMODE) And _
              (InStr(1, etLine1.TAPITSP, "Modem", 1) > 0) Then
               etLine1.PrivilegeNone = True 'set proper priviledge for incompatible modems
              etLine1.DeviceActive = True
              MsgBox ("The program has detected that your device is a (" + etLine1.DeviceName & _
              ") DATA modem and therefore has no voice capabilities." & vbCrLf & vbCrLf & _
              "We will now force a compatibility mode in order to allow you to " & _  
              " continue while greying out options your modem may not support." & 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
          If etLine1.DeviceActive Then
              CommandDial.Enabled = True
          Else
              WriteLog ("Error = " & etLine1.ErrorText)
              CheckActive.Value = 0
          End If
      End If
  End If
End Sub

' **********************************************************************
' ComboDevice_Click - Process device change. If no errors, then it is TAPI
' compliant and so make sure Privileges are set properly
' **********************************************************************
Sub ComboDevice_Click()
  If etLine1.DeviceActive Then CheckActive.Value = 0
  WriteLog ("etLine.DeviceID = " & Str(ComboDevice.ListIndex))
  etLine1.DeviceID = ComboDevice.ListIndex
  If etLine1.ErrorNumber <> 0 Then
      WriteLog (TextCallProgress.Text = TextCallProgress.Text & vbTab & "Error = " & _
      &etLine1.ErrorText)
  Else
      etLine1.PrivilegeMonitor = True
      etLine1.PrivilegeOwner = True
  End If
End Sub

' ********************************************************
' Clear the textbox log
' ********************************************************
Private Sub CommandClear_Click()
    TextCallProgress.Text = ""
End Sub

' ********************************************************
' Display the device configuration screen for
' the TAPI hardware. This is tied to the
' hardware manufacturer's Terminal Service Provider
' or driver, also known as the TSP
' ********************************************************
Private Sub CommandConfigDlg_Click()
    etLine1.DeviceConfigure
End Sub

' ********************************************************
' CommandDial_Click Dial on the etLine device
' ********************************************************
Private Sub CommandDial_Click()
  etLine1.CallHandle = 0 'reset the call handle to 0 to ensure a new call
  etLine1.CallPhoneNumber = TextPhoneNumber.Text
  ' This example uses no call parameters. If you wanted to change the defaults, for example
  ' to tell the defice to use the second address of the line device, you would change the
  ' parameters here like this:
  '
  ' etLine1.Call.Parameters.Defaults := False
  ' etLine1.Call.Parameters.AddressID := 1
  '
  ' See the help file section etLine | Properties | Call | Parameters for more info

  WriteLog ("Dialing [" & TextPhoneNumber.Text & "]")
  ' This is where you dial a call. Rather than executing etLine1.CallDial and having to
  ' check if an error was generated, we use the method as a simple function. By putting
  ' it in an IF statement, we dial the phone and check to see if the result returned was
  ' true of false. See the help file section "How Do I Do That | Make a Call"
  If etLine1.CallDial Then
      CommandDial.Enabled = False
      CommandHangup.Enabled = True
  Else
      ' this will cause the error to be reported twice since we are using a simple
      ' OnError event handler routine also
      WriteLog (vbTab & "Error = " & etLine1.ErrorText)
      CommandHangup_Click 'Just in case the device didn't drop the call
  End If
End Sub

' **********************************************************
' CommandHangup_Click - Hangup the call on the etLine device
' **********************************************************
' Methods like Dial and Hangup return true or false so can be used as shown here
' to combine two functions, dialing or hanging up and checking to see
' if the line was dialing or already hungup.
Private Sub CommandHangup_Click()
  WriteLog ("etLine.Hangup")
  If (etLine1.CallHandle <> 0) And (etLine1.CallState <> LINECALLSTATE_IDLE) Then
      If Not etLine1.CallHangup Then
          WriteLog (vbTab & "The line is already hangup")
      End If
  Else
      WriteLog ("There are no active calls or the Call State is already idle")
  End If
End Sub

' *********************************************************
' Popup TeleScope Utility
' TeleScope is an amazing prototying, testing, debugging, and diagnostic tool
' Click the TeleScope button and watch what happens in it's logs. Place and receive
' calls and a LOT more. See the help file section "Using TeleScope"
' *********************************************************
Private Sub CommandTeleScope_Click()
  etLine1.TeleScopeVisible = True
  WriteLog ("etLine.TeleScopeVisible = True")
End Sub

' *********************************************************
' OnBusy event has fired - phone line is busy
' *********************************************************
Private Sub etLine1_OnBusy(ByVal CallHandle As Long)
  WriteLog ("etLine.OnBusy")
  WriteLog (vbTab & etLine1.StringLINECALLSTATE(etLine1.CallState))
  WriteLog (vbTab & etLine1.StringLINEBUSYMODE(etLine1.CallBusyMode))
  CommandHangup_Click
End Sub

' *********************************************************
' OnCallBegin event has fired
' *********************************************************
Private Sub etLine1_OnCallBegin(ByVal CallHandle As Long)
  WriteLog ("etLine.OnCallBegin")
  WriteLog (vbTab & etLine1.CallBegan)
End Sub

' *********************************************************
' OnCalledID event has fired
' NOTE: Only available on TeleTools Standard Edition and above
' *********************************************************
Private Sub etLine1_OnCalledID(ByVal CallHandle As Long)
  etLine1.CallHandle = CallHandle ' needs to be here for a device that handles multiple calls
  WriteLog ("etLine.OnCalledID" & vbCrLf & vbTab & "CalledIDName = " & etLine1.CallCalledIDName)
  WriteLog (vbTab & "CalledIDNumber = " & etLine1.CallCalledIDNumber)
End Sub

' *********************************************************
' OnCallEnd event has fired
' *********************************************************
Private Sub etLine1_OnCallEnd(ByVal CallHandle As Long)
  WriteLog ("etLine.OnCallEnd")
  WriteLog (vbTab & etLine1.CallEnded)
End Sub

' *********************************************************
' OnCallerId event has fired
' *********************************************************
Private Sub etLine1_OnCallerID(ByVal CallHandle As Long)
  WriteLog ("etLine.OnCallerID" & vbCrLf & vbTab & "CallerIDName = " & etLine1.CallCallerIDName)
  WriteLog (vbTab & "CallerIDNumber = " & etLine1.CallCallerIDNumber)
End Sub

' *************************************************************************
' OnConnected event has fired
' NOTE: Modems report the connected state immediately after dialing
' the phone number. You may not truly be connected!
' *************************************************************************
Private Sub etLine1_OnConnected(ByVal CallHandle As Long)
  WriteLog ("etLine.OnConnected")
  CommandHangup.Enabled = True
End Sub

' ***********************************************************
' OnConnectedID has fired
' NOTE: Only available on TeleTools Professional Edition and above
' ***********************************************************
Private Sub etLine1_OnconnectedID(ByVal CallHandle As Long)
  WriteLog ("etLine.OnConnectedID" & vbCrLf & vbTab & "ConnectedIDName = " & etLine1.CallConnectedIDName)
  WriteLog (vbTab & "ConnectedIDNumber = " & etLine1.CallConnectedIDNumber)
End Sub

' ***********************************************************
' OnDialing event has fired
' ***********************************************************
  Private Sub etLine1_OnDialing(ByVal CallHandle As Long)
  WriteLog ("etLine.OnDialing")
End Sub

' ***********************************************************
' OnDialtone event has fired
' ***********************************************************
Private Sub etLine1_OnDialtone(ByVal CallHandle As Long)
  WriteLog ("etLine.OnDialtone")
End Sub

' ****************************************************************
' OnDisconnected event has fired
' NOTE: Many modems do not report the remote party disconnect!
' ****************************************************************
Private Sub etLine1_OnDisconnected(ByVal CallHandle As Long)
  WriteLog ("etLine.OnDisconnected")
  WriteLog (vbCrLf & etLine1.Disconnected)
  WriteLog (vbTab & "etLine.CallDisconnectMode = " & _
  etLine1.StringLINEDISCONNECTMODE(etLine1.CallDisconnectMode))
CommandHangup_Click
End Sub

' *************************************
' OnError event has fired!
' *************************************
Private Sub etLine1_OnError()
  ' You can process errors in your other routines or use the etLine "OnError" event handler here
  WriteLog ("etLine.OnError" & vbCrLf & vbTab & "etLine.ErrorText = " & etLine1.ErrorText)
End Sub

' *************************************
' OnIdle event has fired
' *************************************
Private Sub etLine1_OnIdle(ByVal CallHandle As Long)
  etLine1.CallHandle = CallHandle
  WriteLog ("etLine.OnIdle")
  CommandHangup.Enabled = False
  CommandDial.Enabled = True
End Sub

' *************************************
' OnOffering event has fired
' *************************************
Private Sub etLine1_OnOffering(ByVal CallHandle As Long)
  WriteLog ("etLine.OnOffering")
End Sub

' *************************************
' OnProceeding event has fired
' NOTE: Only available on TeleTools Standard Edition and above
' *************************************
Private Sub etLine1_OnProceeding(ByVal CallHandle As Long)
  WriteLog ("etLine.OnProceeding")
End Sub

' *************************************
' OnRedirectingID event has fired
' NOTE: Only available on TeleTools Professional Edition and above
' *************************************
Private Sub etLine1_OnRedirectingID(ByVal CallHandle As Long)
  WriteLog ("etLine.OnRedirectingID" & vbCrLf & vbTab & "RedirectingIDName = " & _
     etLine1.CallRedirectingIDName)
End Sub

' *************************************
' OnRedirectionID event has fired
' NOTE: Only available on TeleTools Professional Edition and above
' *************************************
Private Sub etLine1_OnRedirectionID(ByVal CallHandle As Long)
  etLine1.CallHandle = CallHandle
  WriteLog ("etLine.OnRedirectionID" & vbCrLf & vbTab & "RedirectionIDName = " & _
    etLine1.CallRedirectionIDName)
  WriteLog (vbTab & "RedirectionIDNumber = " & etLine1.CallRedirectionIDNumber)
End Sub

' ***********************************
' OnRing event has fired - An incoming call is ringing your line
' ***********************************
Private Sub etLine1_OnRing(ByVal Count As Long, ByVal RingMode As Long)
  WriteLog ("etLine.OnRing [" & Str(Count) & ", " & Str(RingMode) & "]")
End Sub

' ***********************************
' OnRingback event has fired - An outgoing call is successfully ringing
' ***********************************
Private Sub etLine1_OnRingBack(ByVal CallHandle As Long)
  WriteLog ("etLine.OnRingBack")
End Sub

' ***********************************
' OnSpecialInfo event has fired
' NOTE: Only available on TeleTools Standard Edition and above
' ***********************************
Private Sub etLine1_OnSpecialInfo(ByVal CallHandle As Long)
  etLine1.CallHandle = CallHandle
  WriteLog ("etline.OnSpecialInfo")
  WriteLog (vbTab & etLine1.StringLINESPECIALINFO(etLine1.CallSpecialInfo))
End Sub

' **********************************************************************
' WriteLog Function - Write log lines to TextCallProgress box
' **********************************************************************
Function WriteLog(LogText As String) As String
  TextCallProgress.Text = TextCallProgress.Text & LogText & vbCrLf
  TextCallProgress.SelStart = Len(TextCallProgress.Text)
End Function

' *****************************************
' Form Resize - keep controls at
' bottom of form and textbox positioned
' Allows dragging downward to make the log
' screen bigger
' ******************************************
Private Sub Form_Resize()
  If Form1.Height < 3780 Then
      Form1.Height = 3780
  Else
      TextCallProgress.Height = Form1.ScaleHeight - 1900
      CommandConfigDlg.Top = Form1.ScaleHeight - 450
      CommandTeleScope.Top = Form1.ScaleHeight - 450
      CommandInfo.Top = Form1.ScaleHeight - 450
  End If
  If Form1.Width < 4710 Then
      Form1.Width = 4710
  Else
      CommandClear.Left = Form1.ScaleWidth - 1300
      CommandInfo.Left = Form1.ScaleWidth - 490
      TextCallProgress.Width = Form1.ScaleWidth - 240
  End If
End Sub

' ***********************************
' About Box
' ***********************************
Private Sub CommandInfo_Click()
  MsgBox (" etQuickDial Sample Program" & vbCrLf & vbCrLf & "Copyright(c) 2003 ExceleTel Inc." _
    & vbCrLf & vbCrLf & " www.exceletel.com")
End Sub

' ***********************************
' Unload Main Form
' ***********************************
Private Sub Form_Unload(Cancel As Integer)
  ' We would have to close the wave device here if using etPlay and/or etRecord anywhere
  ' CommandHangup_Click, etLine1_OnDisconnected, etLine1_OnIdle and Form_Unload
  ' Decide here if you need to hangup the call since some devices will hangup when the
  ' control is deactivated and some will keep the call active. You may want to not interrup
  ' a call if the application is closed or you may want to ensure that the call is terminated.
  ' Close the etLine control when closing the form
  etLine1.DeviceActive = False
End Sub

READ THIS LINK - C_A P replied to TAPI Programmer on 01-Dec-08 04:51 AM

SOURCE FROM:

http://www.exceletel.com/products/TeleTools/SamplePrograms/etQuickDial/index.htm