home *** CD-ROM | disk | FTP | other *** search
/ Dan Appleman's Visual Bas…s Guide to the Win32 API / Dan.Applmans.Visual.Basic.5.0.Programmers.Guide.To.The.Win32.API.1997.Ziff-Davis.Press.CD / VB5PG32.mdf / vbpg32 / samples4 / ch21 / commdemo.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-03-27  |  4.2 KB  |  139 lines

  1. VERSION 4.00
  2. Begin VB.Form CommDemo 
  3.    Appearance      =   0  'Flat
  4.    BackColor       =   &H80000005&
  5.    Caption         =   "Communications Demo - Mini Terminal"
  6.    ClientHeight    =   4905
  7.    ClientLeft      =   975
  8.    ClientTop       =   1785
  9.    ClientWidth     =   8400
  10.    BeginProperty Font 
  11.       name            =   "MS Sans Serif"
  12.       charset         =   0
  13.       weight          =   700
  14.       size            =   8.25
  15.       underline       =   0   'False
  16.       italic          =   0   'False
  17.       strikethrough   =   0   'False
  18.    EndProperty
  19.    ForeColor       =   &H80000008&
  20.    Height          =   5595
  21.    Left            =   915
  22.    LinkMode        =   1  'Source
  23.    LinkTopic       =   "Form1"
  24.    ScaleHeight     =   4905
  25.    ScaleWidth      =   8400
  26.    Top             =   1155
  27.    Width           =   8520
  28.    Begin VB.Timer Timer1 
  29.       Interval        =   100
  30.       Left            =   240
  31.       Top             =   60
  32.    End
  33.    Begin VB.TextBox TermText 
  34.       Appearance      =   0  'Flat
  35.       BeginProperty Font 
  36.          name            =   "Fixedsys"
  37.          charset         =   0
  38.          weight          =   400
  39.          size            =   9
  40.          underline       =   0   'False
  41.          italic          =   0   'False
  42.          strikethrough   =   0   'False
  43.       EndProperty
  44.       Height          =   4095
  45.       Left            =   120
  46.       MultiLine       =   -1  'True
  47.       ScrollBars      =   3  'Both
  48.       TabIndex        =   0
  49.       Top             =   600
  50.       Width           =   8175
  51.    End
  52.    Begin VB.PictureBox Callback1 
  53.       Appearance      =   0  'Flat
  54.       BackColor       =   &H80000005&
  55.       ForeColor       =   &H80000008&
  56.       Height          =   480
  57.       Left            =   7800
  58.       ScaleHeight     =   450
  59.       ScaleWidth      =   1170
  60.       TabIndex        =   1
  61.       Top             =   120
  62.       Width           =   1200
  63.    End
  64.    Begin VB.Menu MenuConfigure 
  65.       Caption         =   "Configure"
  66.    End
  67.    Begin VB.Menu MenuDial 
  68.       Caption         =   "Dial"
  69.    End
  70. Attribute VB_Name = "CommDemo"
  71. Attribute VB_Creatable = False
  72. Attribute VB_Exposed = False
  73. Option Explicit
  74. ' We open the port and get things started here
  75. Private Sub Form_Load()
  76.     ' We load the configuration form so that the default
  77.     ' settings can be read by OpenThePort
  78.     Commcfg.Show 1
  79.     TermText.Move 0, 0, ScaleWidth, ScaleHeight
  80. End Sub
  81. Private Sub Form_Resize()
  82.     TermText.Move 0, 0, ScaleWidth, ScaleHeight
  83. End Sub
  84. Private Sub Form_Unload(Cancel As Integer)
  85.     Set Comm = Nothing
  86. End Sub
  87. Private Sub MenuConfigure_Click()
  88.     Commcfg.Show 1
  89. End Sub
  90. Private Sub MenuDial_Click()
  91.     Dim dnum$
  92.     If Not (Comm Is Nothing) Then
  93.         TermText.Text = ""
  94.         dnum$ = InputBox$("Enter number to dial", "Dialer")
  95.         Comm.CommOutput "ATTD" + dnum$ + Chr$(13)
  96.     End If
  97. End Sub
  98. Private Sub TermText_KeyPress(KeyAscii As Integer)
  99.     If Not (Comm Is Nothing) Then
  100.         Comm.CommOutput (Chr$(KeyAscii))
  101.     End If
  102.     KeyAscii = 0
  103. End Sub
  104. Public Sub CommInput(thiscomm As dwComm, commdata As String)
  105.     Dim use$
  106.     Dim cpos%
  107.     If commdata <> "" Then
  108.         ' Substitute the CR with a CRLF pair, dump the LF
  109.         
  110.         For cpos% = 1 To Len(commdata$)
  111.             Select Case Asc(Mid$(commdata$, cpos%))
  112.                 Case 13
  113.                     use$ = use$ + Chr$(13) + Chr$(10)
  114.                 Case 10
  115.                     ' Dump the line feeds
  116.                 Case Else
  117.                     use$ = use$ + Mid$(commdata$, cpos%, 1)
  118.             End Select
  119.         Next cpos%
  120.         TermText.SelStart = Len(TermText.Text)
  121.         TermText.SelLength = 0
  122.         TermText.SelText = use$
  123.         
  124.         If Len(TermText.Text) > 4096 Then
  125.             TermText.Text = Right$(TermText.Text, 2048)
  126.         End If
  127.         TermText.SelStart = Len(TermText.Text)
  128.         
  129.     End If
  130. End Sub
  131. Public Sub CommEvent(thiscomm As dwComm, ev As String)
  132.     TermText.SelStart = Len(TermText.Text)
  133.     TermText.SelText = vbCrLf & ev & vbCrLf
  134.     TermText.SelStart = Len(TermText.Text)
  135. End Sub
  136. Private Sub Timer1_Timer()
  137.     If Not (Comm Is Nothing) Then Comm.Poll
  138. End Sub
  139.