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 / samples5 / ch21 / commdemo.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-17  |  4.3 KB  |  140 lines

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