home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Programmer'…arterly (Limited Edition) / Visual_Basic_Programmers_Journal_VB-CD_Quarterly_Limited_Edition_1995.iso / code / ch18code / termset.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-09-28  |  14.4 KB  |  481 lines

  1. VERSION 4.00
  2. Begin VB.Form ConfigScrn 
  3.    BorderStyle     =   3  'Fixed Double
  4.    Caption         =   "Communication Settings"
  5.    ClientHeight    =   3840
  6.    ClientLeft      =   1110
  7.    ClientTop       =   1530
  8.    ClientWidth     =   4980
  9.    BeginProperty Font 
  10.       name            =   "MS Sans Serif"
  11.       charset         =   0
  12.       weight          =   400
  13.       size            =   8.25
  14.       underline       =   0   'False
  15.       italic          =   0   'False
  16.       strikethrough   =   0   'False
  17.    EndProperty
  18.    Height          =   4245
  19.    Icon            =   0
  20.    Left            =   1050
  21.    ScaleHeight     =   3840
  22.    ScaleWidth      =   4980
  23.    Top             =   1185
  24.    Width           =   5100
  25.    Begin VB.OptionButton ComPort 
  26.       Caption         =   "Com1"
  27.       Height          =   252
  28.       Index           =   1
  29.       Left            =   1920
  30.       TabIndex        =   31
  31.       Top             =   2340
  32.       Width           =   852
  33.    End
  34.    Begin VB.OptionButton ComPort 
  35.       Caption         =   "Com4"
  36.       Height          =   252
  37.       Index           =   4
  38.       Left            =   1920
  39.       TabIndex        =   30
  40.       Top             =   3240
  41.       Width           =   852
  42.    End
  43.    Begin VB.OptionButton ComPort 
  44.       Caption         =   "Com3"
  45.       Height          =   252
  46.       Index           =   3
  47.       Left            =   1920
  48.       TabIndex        =   29
  49.       Top             =   2940
  50.       Width           =   852
  51.    End
  52.    Begin VB.OptionButton ComPort 
  53.       Caption         =   "Com2"
  54.       Height          =   252
  55.       Index           =   2
  56.       Left            =   1920
  57.       TabIndex        =   28
  58.       Top             =   2640
  59.       Width           =   852
  60.    End
  61.    Begin VB.Frame Frame1 
  62.       Caption         =   "&Baud Rate"
  63.       Height          =   975
  64.       Left            =   240
  65.       TabIndex        =   2
  66.       Top             =   120
  67.       Width           =   3315
  68.       Begin VB.OptionButton Baud3 
  69.          Caption         =   "300"
  70.          Height          =   255
  71.          Left            =   300
  72.          TabIndex        =   3
  73.          Top             =   240
  74.          Width           =   735
  75.       End
  76.       Begin VB.OptionButton Baud6 
  77.          Caption         =   "600"
  78.          Height          =   255
  79.          Left            =   1260
  80.          TabIndex        =   4
  81.          Top             =   240
  82.          Width           =   615
  83.       End
  84.       Begin VB.OptionButton Baud12 
  85.          Caption         =   "1200"
  86.          Height          =   255
  87.          Left            =   2220
  88.          TabIndex        =   5
  89.          Top             =   240
  90.          Width           =   735
  91.       End
  92.       Begin VB.OptionButton Baud24 
  93.          Caption         =   "2400"
  94.          Height          =   255
  95.          Left            =   300
  96.          TabIndex        =   6
  97.          Top             =   600
  98.          Width           =   735
  99.       End
  100.       Begin VB.OptionButton Baud48 
  101.          Caption         =   "4800"
  102.          Height          =   255
  103.          Left            =   1260
  104.          TabIndex        =   7
  105.          Top             =   600
  106.          Width           =   735
  107.       End
  108.       Begin VB.OptionButton Baud96 
  109.          Caption         =   "9600"
  110.          Height          =   255
  111.          Left            =   2220
  112.          TabIndex        =   8
  113.          Top             =   600
  114.          Width           =   735
  115.       End
  116.    End
  117.    Begin VB.CommandButton OKButton 
  118.       Caption         =   "OK"
  119.       Default         =   -1  'True
  120.       Height          =   375
  121.       Left            =   3780
  122.       TabIndex        =   0
  123.       Top             =   240
  124.       Width           =   975
  125.    End
  126.    Begin VB.CommandButton CancelButton 
  127.       Cancel          =   -1  'True
  128.       Caption         =   "Cancel"
  129.       Height          =   375
  130.       Left            =   3780
  131.       TabIndex        =   1
  132.       Top             =   720
  133.       Width           =   975
  134.    End
  135.    Begin VB.Frame Frame2 
  136.       Caption         =   "&Data Bits"
  137.       Height          =   615
  138.       Left            =   240
  139.       TabIndex        =   9
  140.       Top             =   1260
  141.       Width           =   1275
  142.       Begin VB.OptionButton Data7 
  143.          Caption         =   "7"
  144.          Height          =   255
  145.          Left            =   180
  146.          TabIndex        =   10
  147.          Top             =   240
  148.          Width           =   375
  149.       End
  150.       Begin VB.OptionButton Data8 
  151.          Caption         =   "8"
  152.          Height          =   255
  153.          Left            =   720
  154.          TabIndex        =   11
  155.          Top             =   240
  156.          Width           =   435
  157.       End
  158.    End
  159.    Begin VB.Frame Frame3 
  160.       Caption         =   "&Stop Bits"
  161.       Height          =   615
  162.       Left            =   1740
  163.       TabIndex        =   12
  164.       Top             =   1260
  165.       Width           =   1335
  166.       Begin VB.OptionButton Stop1 
  167.          Caption         =   "1"
  168.          Height          =   255
  169.          Left            =   240
  170.          TabIndex        =   13
  171.          Top             =   240
  172.          Width           =   435
  173.       End
  174.       Begin VB.OptionButton Stop2 
  175.          Caption         =   "2"
  176.          Height          =   255
  177.          Left            =   780
  178.          TabIndex        =   14
  179.          Top             =   240
  180.          Width           =   495
  181.       End
  182.    End
  183.    Begin VB.Frame Frame7 
  184.       Caption         =   "&Echo"
  185.       Height          =   615
  186.       Left            =   3300
  187.       TabIndex        =   15
  188.       Top             =   1260
  189.       Width           =   1455
  190.       Begin VB.OptionButton EchoOff 
  191.          Caption         =   "Off"
  192.          Height          =   315
  193.          Left            =   780
  194.          TabIndex        =   17
  195.          Top             =   240
  196.          Width           =   615
  197.       End
  198.       Begin VB.OptionButton EchoOn 
  199.          Caption         =   "On"
  200.          Height          =   195
  201.          Left            =   180
  202.          TabIndex        =   16
  203.          Top             =   300
  204.          Width           =   555
  205.       End
  206.    End
  207.    Begin VB.Frame Frame4 
  208.       Caption         =   "&Parity"
  209.       Height          =   1575
  210.       Left            =   240
  211.       TabIndex        =   18
  212.       Top             =   2040
  213.       Width           =   1275
  214.       Begin VB.OptionButton NoParity 
  215.          Caption         =   "None"
  216.          Height          =   255
  217.          Left            =   180
  218.          TabIndex        =   19
  219.          Top             =   300
  220.          Width           =   855
  221.       End
  222.       Begin VB.OptionButton OddParity 
  223.          Caption         =   "Odd"
  224.          Height          =   255
  225.          Left            =   180
  226.          TabIndex        =   20
  227.          Top             =   600
  228.          Width           =   735
  229.       End
  230.       Begin VB.OptionButton EvenParity 
  231.          Caption         =   "Even"
  232.          Height          =   255
  233.          Left            =   180
  234.          TabIndex        =   21
  235.          Top             =   900
  236.          Width           =   855
  237.       End
  238.    End
  239.    Begin VB.Frame Frame6 
  240.       Caption         =   "&Com Port"
  241.       Height          =   1575
  242.       Left            =   1740
  243.       TabIndex        =   22
  244.       Top             =   2040
  245.       Width           =   1335
  246.    End
  247.    Begin VB.Frame Frame5 
  248.       Caption         =   "&Flow Control"
  249.       Height          =   1575
  250.       Left            =   3300
  251.       TabIndex        =   23
  252.       Top             =   2040
  253.       Width           =   1455
  254.       Begin VB.OptionButton NoFlow 
  255.          Caption         =   "None"
  256.          Height          =   255
  257.          Left            =   180
  258.          TabIndex        =   26
  259.          Top             =   300
  260.          Width           =   855
  261.       End
  262.       Begin VB.OptionButton XonFlow 
  263.          Caption         =   "Xon/Xoff"
  264.          Height          =   255
  265.          Left            =   180
  266.          TabIndex        =   24
  267.          Top             =   600
  268.          Width           =   1095
  269.       End
  270.       Begin VB.OptionButton RTSFlow 
  271.          Caption         =   "RTS"
  272.          Height          =   255
  273.          Left            =   180
  274.          TabIndex        =   25
  275.          Top             =   900
  276.          Width           =   735
  277.       End
  278.       Begin VB.OptionButton BothFlow 
  279.          Caption         =   "Xon/RTS"
  280.          Height          =   255
  281.          Left            =   180
  282.          TabIndex        =   27
  283.          Top             =   1200
  284.          Width           =   1155
  285.       End
  286.    End
  287. Attribute VB_Name = "ConfigScrn"
  288. Attribute VB_Creatable = False
  289. Attribute VB_Exposed = False
  290. ' Communication Settings Configuration Form
  291. ' Copyright (c) 1994, Crescent Software
  292. DefInt A-Z
  293. Dim Shared NewPort                 ' Temporary configuration settings.
  294. Dim Shared NewBaud$, NewParity$
  295. Dim Shared NewData$, NewStop$
  296. Dim Shared NewShake
  297. ' 1200 baud option button.
  298. Private Sub Baud12_Click()
  299.     NewBaud$ = "1200"
  300. End Sub
  301. ' 2400 baud option button.
  302. Private Sub Baud24_Click()
  303.     NewBaud$ = "2400"
  304. End Sub
  305. ' 300 baud option button.
  306. Private Sub Baud3_Click()
  307.     NewBaud$ = "300"
  308. End Sub
  309. ' 4800 baud option button.
  310. Private Sub Baud48_Click()
  311.     NewBaud$ = "4800"
  312. End Sub
  313. ' 600 baud option button.
  314. Private Sub Baud6_Click()
  315.     NewBaud$ = "600"
  316. End Sub
  317. ' 9600 baud option button.
  318. Private Sub Baud96_Click()
  319.     NewBaud$ = "9600"
  320. End Sub
  321. ' Both RTS and Xon/Xoff handshaking option button.
  322. Private Sub BothFlow_Click()
  323.     NewShake = 3
  324. End Sub
  325. ' Cancel button actions.
  326. Private Sub CancelButton_Click()
  327.     Unload ConfigScrn
  328. End Sub
  329. Private Sub ComPort_Click(Index As Integer)
  330.     NewPort = Index
  331. End Sub
  332. ' 7 data bits option button.
  333. Private Sub Data7_Click()
  334.     NewData$ = "7"
  335. End Sub
  336. ' 8 data bits option button.
  337. Private Sub Data8_Click()
  338.     NewData$ = "8"
  339. End Sub
  340. ' Echo Off option button.
  341. Private Sub EchoOff_Click()
  342.     Echo = 0
  343. End Sub
  344. ' Echo On option button.
  345. Private Sub EchoOn_Click()
  346.     Echo = True
  347. End Sub
  348. ' Even Parity option button.
  349. Private Sub EvenParity_Click()
  350.     NewParity$ = "E"
  351. End Sub
  352. ' Initialize and display the configuration form.
  353. Private Sub Form_Load()
  354.     ' Get the current port.
  355.     Port = Form1.MSComm1.CommPort
  356.     ConfigScrn.ComPort(Port).Value = True   ' Set the option button.
  357.     ' Get the current baud.
  358.     FirstComma = InStrB(Form1.MSComm1.Settings, ",")
  359.     Baud$ = Left$(Form1.MSComm1.Settings, FirstComma - 1)
  360.     Select Case Val(Baud$)                  ' Select baud.
  361.     Case 300                                ' Set the active baud option button.
  362.         ConfigScrn.Baud3.Value = True
  363.     Case 600
  364.         ConfigScrn.Baud6.Value = True
  365.     Case 1200
  366.         ConfigScrn.Baud12.Value = True
  367.     Case 2400
  368.         ConfigScrn.Baud24.Value = True
  369.     Case 4800
  370.         ConfigScrn.Baud48.Value = True
  371.     Case 9600
  372.         ConfigScrn.Baud96.Value = True
  373.     End Select
  374.     ' Get the current parity.
  375.     Parity$ = Mid$(Form1.MSComm1.Settings, FirstComma + 1, 1)
  376.     Select Case UCase$(Parity$)              ' Select parity.
  377.     Case "N"                                 ' Set the active parity option button.
  378.         ConfigScrn.NoParity.Value = True
  379.     Case "E"
  380.         ConfigScrn.EvenParity.Value = True
  381.     Case "O"
  382.         ConfigScrn.OddParity.Value = True
  383.     End Select
  384.     ' Get the data bits.
  385.     SecondComma = FirstComma + 2
  386.     DBits$ = Mid$(Form1.MSComm1.Settings, SecondComma + 1, 1)
  387.     Select Case Val(DBits$)                 ' Select data bits.
  388.     Case 7                                  ' Set the active choice option button.
  389.         ConfigScrn.Data7.Value = True
  390.     Case 8
  391.         ConfigScrn.Data8.Value = True
  392.     End Select
  393.     ' Get the stop bits.
  394.     ThirdComma = SecondComma + 2
  395.     SBits$ = Mid$(Form1.MSComm1.Settings, ThirdComma + 1, 1)
  396.     Select Case Val(SBits$)                 ' Select stop bits.
  397.     Case 1                                  ' Set the active choice option button.
  398.         ConfigScrn.Stop1.Value = True
  399.     Case 2
  400.         ConfigScrn.Stop2.Value = True
  401.     End Select
  402.     Select Case Form1.MSComm1.Handshaking
  403.     Case 0                                  ' Set active choice option button.
  404.         ConfigScrn.NoFlow.Value = True
  405.     Case 1
  406.         ConfigScrn.XonFlow.Value = True
  407.     Case 2
  408.         ConfigScrn.RTSFlow.Value = True
  409.     Case 3
  410.         ConfigScrn.BothFlow.Value = True
  411.     End Select
  412.     If Echo Then
  413.         ConfigScrn.EchoOn.Value = True
  414.     Else
  415.         ConfigScrn.EchoOff.Value = True
  416.     End If
  417. End Sub
  418. ' No handshaking option button.
  419. Private Sub NoFlow_Click()
  420.     NewShake = 0
  421. End Sub
  422. ' No Parity option button.
  423. Private Sub NoParity_Click()
  424.     NewParity$ = "N"
  425. End Sub
  426. ' Odd Parity option button.
  427. Private Sub OddParity_Click()
  428.     NewParity$ = "O"
  429. End Sub
  430. ' OK button actions.
  431. Private Sub OkButton_Click()
  432.     On Error Resume Next
  433.     OldPort = Form1.MSComm1.CommPort
  434.     If NewPort <> OldPort Then                    ' If the port number changes, close the old port.
  435.         If Form1.MSComm1.PortOpen Then
  436.            Form1.MSComm1.PortOpen = False
  437.            ReOpen = True
  438.         End If
  439.         Form1.MSComm1.CommPort = NewPort          ' Set the new port number.
  440.         If Err = 0 Then
  441.            If ReOpen Then
  442.               Form1.MSComm1.PortOpen = True
  443.               Form1.MOpen.Checked = Form1.MSComm1.PortOpen
  444.               Form1.MSendText.Enabled = Form1.MSComm1.PortOpen
  445.            End If
  446.         End If
  447.         If Err Then
  448.            MsgBox Error$, 48
  449.            Form1.MSComm1.CommPort = OldPort
  450.            Exit Sub
  451.         End If
  452.     End If
  453.     Form1.MSComm1.Settings = NewBaud$ + "," + NewParity$ + "," + NewData$ + "," + NewStop$
  454.     If Err Then
  455.        MsgBox Error$, 48
  456.        Exit Sub
  457.     End If
  458.     Form1.MSComm1.Handshaking = NewShake
  459.     If Err Then
  460.        MsgBox Error$, 48
  461.        Exit Sub
  462.     End If
  463.     Unload ConfigScrn                               ' Unload the configuration form.
  464. End Sub
  465. ' RTS handshaking option button.
  466. Private Sub RTSFlow_Click()
  467.     NewShake = 2
  468. End Sub
  469. ' 1 stop bit option button.
  470. Private Sub Stop1_Click()
  471.     NewStop$ = "1"
  472. End Sub
  473. ' 2 stop bits option button.
  474. Private Sub Stop2_Click()
  475.     NewStop$ = "2"
  476. End Sub
  477. ' XON handshaking option button.
  478. Private Sub XonFlow_Click()
  479.     NewShake = 1
  480. End Sub
  481.