How to Make Telephone Calls With Visual Basic

Written by jaime avelar
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Make Telephone Calls With Visual Basic
Automate telephone calls with VB.NET. (telephone image by MATTHIEU FABISIAK from Fotolia.com)

Having the knowledge of how to make telephone calls from a Microsoft Visual Basic.NET (VB.NET) application can save you time if you need to make calls continuously. VB.NET is a computer programming language used to create mobile, Web and desktop applications. Making telephone calls from VB.NET can be accomplished using the Telephony Application Programming Interface (TAPI). TAPI gives the programmers the layers needed to access the Microsoft Telephony DLLs (dynamic link libraries). Telephony integrates computers with devices such as cameras and Internet networks.

Skill level:
Moderate

Other People Are Reading

Things you need

  • Microsoft Visual Basic Express

Show MoreHide

Instructions

  1. 1

    Start Microsoft Visual Basic Express, click "New Project..." on the left pane of your screen and select "Windows Forms Application." Click "OK."

  2. 2

    Double-click "Button" on the "Toolbox" to add a new button. Double-click "Label" to add a label. Add a second label using the same process. Double-click "TextBox" to add a text box.

  3. 3

    Double-click "Button1" to open the "Form1.vb"module. Copy and paste the following in the very first line of the module:

    Imports System.Windows.Forms

  4. 4

    Copy and paste the following to declare the TAPI32 DLL under "Public Class Form1" but above the "Button1_Click" procedure:

    Declare Auto Function tapiRequestMakeCall Lib "TAPI32.dll" _
    
        (ByVal DestAddress As String, ByVal AppName As String, _
    
         ByVal CalledParty As String, ByVal Comment As String) As Integer
    
    Const TAPIERR_NOREQUESTRECIPIENT As Short = -2
    
    Const TAPIERR_REQUESTQUEUEFULL As Short = -3
    
    Const TAPIERR_INVALDESTADDRESS As Short = -4
    

    The "Button1_Click" procedure was created when you double-clicked "Button1" on your Form.

  5. 5

    Copy and paste the following inside the "Button1_Click" procedure to create your variables:

        Dim phoneNum As String
    
        Dim tResult As Short
    
        Dim tmpStr As String
    

    The "Button1_Click" procedure was created when you double-clicked "Button1" on your Form.

  6. 6

    Copy and paste the following to get the phone number entered in the text box and call it:

    phoneNum = Trim(TextBox1.Text)

        Try
    
            tResult = tapiRequestMakeCall(phoneNum, "Dial", phoneNum, "")
    
        Catch ex As Exception
    
            Label2.Text = "Error"
    
        End Try
    
  7. 7

    Copy and paste the following to check for errors:

        If tResult <> 0 Then
    
            tmpStr = "Error"
    
            Select Case tResult
    
                Case TAPIERR_NOREQUESTRECIPIENT
    
                    tmpStr = tmpStr & "No windows Telephony dialling application  is running and none could be started."
    
                Case TAPIERR_REQUESTQUEUEFULL
    
                    tmpStr = tmpStr & "The queue of pending Windows Telephony dialling requests is full."
    
                Case TAPIERR_INVALDESTADDRESS
    
                    tmpStr = tmpStr & "The phone number is not valid."
    
                Case Else
    
                    tmpStr = tmpStr & "Unkown error."
    
            End Select
    
        Else
    
            tmpStr = "Dialling"
    
        End If
    
        Label2.Text = tmpStr
    
    
    
    End Sub
    

    End Class

  8. 8

    Press "F5" to run your program, then enter a phone number in the text box and click "Button1."

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.