home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual BASIC 5.0 (Ent. Edition) / Vb5ent Extractor.EXE / VB / SAMPLES / COMPTOOL / DIALER / DIALER.FRM (.txt) next >
Encoding:
Visual Basic Form  |  1996-10-15  |  6.1 KB  |  183 lines

  1. VERSION 5.00
  2. Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
  3. Begin VB.Form DIALER 
  4.    Caption         =   "MSComm Phone Dialer"
  5.    ClientHeight    =   1545
  6.    ClientLeft      =   4005
  7.    ClientTop       =   3270
  8.    ClientWidth     =   4275
  9.    LinkTopic       =   "Form2"
  10.    PaletteMode     =   1  'UseZOrder
  11.    ScaleHeight     =   1545
  12.    ScaleWidth      =   4275
  13.    WhatsThisHelp   =   -1  'True
  14.    Begin MSCommLib.MSComm MSComm1 
  15.       Left            =   0
  16.       Top             =   0
  17.       _ExtentX        =   1005
  18.       _ExtentY        =   1005
  19.       DTREnable       =   -1  'True
  20.    End
  21.    Begin VB.CommandButton CancelButton 
  22.       Caption         =   "Cancel"
  23.       Enabled         =   0   'False
  24.       BeginProperty Font 
  25.          Name            =   "MS Sans Serif"
  26.          Size            =   8.25
  27.          Charset         =   0
  28.          Weight          =   700
  29.          Underline       =   0   'False
  30.          Italic          =   0   'False
  31.          Strikethrough   =   0   'False
  32.       EndProperty
  33.       Height          =   348
  34.       Left            =   1680
  35.       TabIndex        =   3
  36.       Top             =   885
  37.       Width           =   852
  38.    End
  39.    Begin VB.CommandButton QuitButton 
  40.       Cancel          =   -1  'True
  41.       Caption         =   "Quit"
  42.       BeginProperty Font 
  43.          Name            =   "MS Sans Serif"
  44.          Size            =   8.25
  45.          Charset         =   0
  46.          Weight          =   700
  47.          Underline       =   0   'False
  48.          Italic          =   0   'False
  49.          Strikethrough   =   0   'False
  50.       EndProperty
  51.       Height          =   348
  52.       Left            =   2640
  53.       TabIndex        =   1
  54.       Top             =   885
  55.       Width           =   852
  56.    End
  57.    Begin VB.CommandButton DialButton 
  58.       Caption         =   "Dial"
  59.       Default         =   -1  'True
  60.       BeginProperty Font 
  61.          Name            =   "MS Sans Serif"
  62.          Size            =   8.25
  63.          Charset         =   0
  64.          Weight          =   700
  65.          Underline       =   0   'False
  66.          Italic          =   0   'False
  67.          Strikethrough   =   0   'False
  68.       EndProperty
  69.       Height          =   348
  70.       Left            =   720
  71.       TabIndex        =   0
  72.       Top             =   885
  73.       Width           =   852
  74.    End
  75.    Begin VB.Label Status 
  76.       BorderStyle     =   1  'Fixed Single
  77.       Caption         =   "To dial a number, click the Dial button"
  78.       Height          =   255
  79.       Left            =   720
  80.       TabIndex        =   2
  81.       Top             =   360
  82.       Width           =   2775
  83.    End
  84. Attribute VB_Name = "DIALER"
  85. Attribute VB_GlobalNameSpace = False
  86. Attribute VB_Creatable = False
  87. Attribute VB_TemplateDerived = False
  88. Attribute VB_PredeclaredId = True
  89. Attribute VB_Exposed = False
  90. '--------------------------------------------------------
  91. '   DIALER.FRM
  92. '   Copyright (c) 1994 Crescent Software, Inc.
  93. '   by Carl Franklin
  94. '   Updated by Anton de Jong
  95. '   Demonstrates how to dial phone numbers with a modem.
  96. '   For this program to work, your telephone and
  97. '   modem must be connected to the same phone line.
  98. '--------------------------------------------------------
  99. Option Explicit
  100. DefInt A-Z
  101. ' This flag is set when the user chooses Cancel.
  102. Dim CancelFlag
  103. Private Sub CancelButton_Click()
  104.     ' CancelFlag tells the Dial procedure to exit.
  105.     CancelFlag = True
  106.     CancelButton.Enabled = False
  107. End Sub
  108. Private Sub Dial(Number$)
  109.     Dim DialString$, FromModem$, dummy
  110.     ' AT is the Hayes compatible ATTENTION command and is required to send commands to the modem.
  111.     ' DT means "Dial Tone." The Dial command uses touch tones, as opposed to pulse (DP = Dial Pulse).
  112.     ' Numbers$ is the phone number being dialed.
  113.     ' A semicolon tells the modem to return to command mode after dialing (important).
  114.     ' A carriage return, vbCr, is required when sending commands to the modem.
  115.     DialString$ = "ATDT" + Number$ + ";" + vbCr
  116.     ' Communications port settings.
  117.     ' Assuming that a mouse is attached to COM1, CommPort is set to 2
  118.     MSComm1.CommPort = 2
  119.     MSComm1.Settings = "9600,N,8,1"
  120.     ' Open the communications port.
  121.     On Error Resume Next
  122.     MSComm1.PortOpen = True
  123.     If Err Then
  124.        MsgBox "COM2: not available. Change the CommPort property to another port."
  125.        Exit Sub
  126.     End If
  127.     ' Flush the input buffer.
  128.     MSComm1.InBufferCount = 0
  129.     ' Dial the number.
  130.     MSComm1.Output = DialString$
  131.     ' Wait for "OK" to come back from the modem.
  132.     Do
  133.        dummy = DoEvents()
  134.        ' If there is data in the buffer, then read it.
  135.        If MSComm1.InBufferCount Then
  136.           FromModem$ = FromModem$ + MSComm1.Input
  137.           ' Check for "OK".
  138.           If InStr(FromModem$, "OK") Then
  139.              ' Notify the user to pick up the phone.
  140.              Beep
  141.              MsgBox "Please pick up the phone and either press Enter or click OK"
  142.              Exit Do
  143.           End If
  144.        End If
  145.         
  146.        ' Did the user choose Cancel?
  147.        If CancelFlag Then
  148.           CancelFlag = False
  149.           Exit Do
  150.        End If
  151.     Loop
  152.     ' Disconnect the modem.
  153.     MSComm1.Output = "ATH" + vbCr
  154.     ' Close the port.
  155.     MSComm1.PortOpen = False
  156. End Sub
  157. Private Sub DialButton_Click()
  158.     Dim Number$, Temp$
  159.     DialButton.Enabled = False
  160.     QuitButton.Enabled = False
  161.     CancelButton.Enabled = True
  162.     ' Get the number to dial.
  163.     Number$ = InputBox$("Enter phone number:", Number$)
  164.         If Number$ = "" Then Exit Sub
  165.     Temp$ = Status
  166.     Status = "Dialing - " + Number$
  167.     ' Dial the selected phone number.
  168.     Dial Number$
  169.     DialButton.Enabled = True
  170.     QuitButton.Enabled = True
  171.     CancelButton.Enabled = False
  172.     Status = Temp$
  173. End Sub
  174. Private Sub Form_Load()
  175.     ' Setting InputLen to 0 tells MSComm to read the entire
  176.     ' contents of the input buffer when the Input property
  177.     ' is used.
  178.     MSComm1.InputLen = 0
  179. End Sub
  180. Private Sub QuitButton_Click()
  181.     End
  182. End Sub
  183.