Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents lblMsg As System.Windows.Forms.Label Friend WithEvents cmdDial As System.Windows.Forms.Button Friend WithEvents cmdCancel As System.Windows.Forms.Button Friend WithEvents MSComm1 As AxMSCommLib.AxMSComm Private Sub InitializeComponent() Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1)) Me.MSComm1 = New AxMSCommLib.AxMSComm Me.lblMsg = New System.Windows.Forms.Label Me.cmdDial = New System.Windows.Forms.Button Me.cmdCancel = New System.Windows.Forms.Button CType(Me.MSComm1, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() ' 'MSComm1 ' Me.MSComm1.Enabled = True Me.MSComm1.Location = New System.Drawing.Point(120, 224) Me.MSComm1.Name = "MSComm1" Me.MSComm1.OcxState = CType(resources.GetObject("MSComm1.OcxState"), System.Windows.Forms.AxHost.State) Me.MSComm1.Size = New System.Drawing.Size(38, 38) Me.MSComm1.TabIndex = 0 ' 'lblMsg ' Me.lblMsg.Location = New System.Drawing.Point(88, 56) Me.lblMsg.Name = "lblMsg" Me.lblMsg.TabIndex = 2 Me.lblMsg.Text = "Label1" ' 'cmdDial ' Me.cmdDial.Location = New System.Drawing.Point(32, 152) Me.cmdDial.Name = "cmdDial" Me.cmdDial.TabIndex = 3 Me.cmdDial.Text = "Button1" ' 'cmdCancel ' Me.cmdCancel.Location = New System.Drawing.Point(192, 152) Me.cmdCancel.Name = "cmdCancel" Me.cmdCancel.TabIndex = 4 Me.cmdCancel.Text = "Button2" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 273) Me.Controls.Add(Me.cmdCancel) Me.Controls.Add(Me.cmdDial) Me.Controls.Add(Me.lblMsg) Me.Controls.Add(Me.MSComm1) Me.Name = "Form1" Me.Text = "Form1" CType(Me.MSComm1, System.ComponentModel.ISupportInitialize).EndInit() Me.ResumeLayout(False) End Sub #End Region Option Explicit ' This flag is set when the user chooses Cancel. Dim CancelFlag Private Sub cmdCancel_Click() ' CancelFlag tells the Dial procedure to exit. CancelFlag = True cmdCancel.Enabled = False End Sub Private Sub Dial(Number As String) Dim DialString As String, FromModem As String, dummy As String ' AT is the Hayes compatible ATTENTION command and is required to send commands to the modem. ' DT means "Dial Tone." The Dial command uses touch tones, as opposed to pulse (DP = Dial Pulse). ' Numbers is the phone number being dialed. ' A semicolon tells the modem to return to command mode after dialing (important). ' A carriage return, vbCr, is required when sending commands to the modem. DialString = "ATDT" + Number + ";" + vbCr ' Communications port settings. ' Assuming that a mouse is attached to COM1, CommPort is set to 2 MSComm1.CommPort = 3 MSComm1.Settings = "9600,N,8,1" ' Open the communications port. On Error Resume Next MSComm1.PortOpen = True If Err Then MsgBox "COM" & MSComm1.CommPort & ": 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. Do dummy = DoEvents() ' If there is data in the buffer, then read it. If MSComm1.InBufferCount Then FromModem = FromModem + MSComm1.Input ' Check for "OK". If InStr(FromModem, "OK") Then ' Notify the user to pick up the phone. Beep MsgBox "Please pick up the phone and either press Enter or click OK" Exit Do End If End If ' Did the user choose Cancel? If CancelFlag Then CancelFlag = False Exit Do End If Loop ' Disconnect the modem. MSComm1.Output = "ATH" + vbCr ' Close the port. MSComm1.PortOpen = False End Sub Private Sub cmdDial_Click() Dim Number As String, Temp As String cmdDial.Enabled = False cmdCancel.Enabled = True ' Get the number to dial. Number = InputBox("Enter phone number:", Number) If Number = "" Then Exit Sub Temp = lblMsg lblMsg = "Dialing - " + Number ' Dial the selected phone number. Dial Number cmdDial.Enabled = True cmdCancel.Enabled = False lblMsg = Temp End Sub Private Sub Form_Load() ' Setting InputLen to 0 tells MSComm to read the entire ' contents of the input buffer when the Input property ' is used. MSComm1.InputLen = 0 End Sub End Class