home *** CD-ROM | disk | FTP | other *** search
/ On Hand / On_Hand_From_Softbank_1994_Release_2_Disc_2_1994.iso / 00202 / s / disk1 / vbterm.fr_ / vbterm.bin
Text File  |  1993-04-28  |  19KB  |  696 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "MSComm Terminal "
  5.    ForeColor       =   &H00000000&
  6.    Height          =   3945
  7.    Icon            =   VBTERM.FRX:0000
  8.    Left            =   870
  9.    LinkMode        =   1  'Source
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   3255
  12.    ScaleWidth      =   7470
  13.    Top             =   1050
  14.    Width           =   7590
  15.    Begin CommonDialog OpenLog 
  16.       CancelError     =   -1  'True
  17.       Color           =   &H00C0C0C0&
  18.       DefaultExt      =   "LOG"
  19.       DialogTitle     =   "Open Communications Log File"
  20.       Filename        =   "*.log"
  21.       Filter          =   "*.log"
  22.       Left            =   120
  23.       Top             =   900
  24.    End
  25.    Begin MSComm MSComm1 
  26.       CommPort        =   2
  27.       InBufferSize    =   8192
  28.       Interval        =   1000
  29.       Left            =   120
  30.       RThreshold      =   1
  31.       Settings        =   "2400,n,8,1"
  32.       Top             =   420
  33.    End
  34.    Begin TextBox Term 
  35.       BorderStyle     =   0  'None
  36.       Height          =   516
  37.       Left            =   768
  38.       MultiLine       =   -1  'True
  39.       ScrollBars      =   3  'Both
  40.       TabIndex        =   0
  41.       Top             =   480
  42.       Width           =   1116
  43.    End
  44.    Begin Label Label2 
  45.       BackColor       =   &H00C0C0C0&
  46.       Caption         =   "Status - "
  47.       Height          =   192
  48.       Left            =   120
  49.       TabIndex        =   2
  50.       Top             =   0
  51.       Width           =   732
  52.    End
  53.    Begin Line Line1 
  54.       BorderColor     =   &H00808080&
  55.       BorderWidth     =   3
  56.       X1              =   0
  57.       X2              =   7320
  58.       Y1              =   240
  59.       Y2              =   240
  60.    End
  61.    Begin Label Label1 
  62.       BackColor       =   &H00C0C0C0&
  63.       Height          =   192
  64.       Left            =   840
  65.       TabIndex        =   1
  66.       Top             =   0
  67.       Width           =   6612
  68.    End
  69.    Begin Menu MFile 
  70.       Caption         =   "&File"
  71.       Begin Menu MOpenLog 
  72.          Caption         =   "&Open Log File..."
  73.       End
  74.       Begin Menu MCloseLog 
  75.          Caption         =   "&Close Log File"
  76.          Enabled         =   0   'False
  77.       End
  78.       Begin Menu M3 
  79.          Caption         =   "-"
  80.       End
  81.       Begin Menu MSendText 
  82.          Caption         =   "&Transmit Text File..."
  83.          Enabled         =   0   'False
  84.       End
  85.       Begin Menu Bar2 
  86.          Caption         =   "-"
  87.       End
  88.       Begin Menu MFileExit 
  89.          Caption         =   "E&xit"
  90.       End
  91.    End
  92.    Begin Menu MPort 
  93.       Caption         =   "&CommPort"
  94.       Begin Menu MOpen 
  95.          Caption         =   "Port &Open"
  96.       End
  97.       Begin Menu MSettings 
  98.          Caption         =   "&Settings..."
  99.       End
  100.       Begin Menu MBar1 
  101.          Caption         =   "-"
  102.       End
  103.       Begin Menu MDial 
  104.          Caption         =   "&Dial Phone Number..."
  105.       End
  106.       Begin Menu MHangup 
  107.          Caption         =   "&Hang Up Phone"
  108.          Enabled         =   0   'False
  109.       End
  110.    End
  111.    Begin Menu MProp 
  112.       Caption         =   "&Properties"
  113.       Begin Menu MInputLen 
  114.          Caption         =   "&InputLen..."
  115.       End
  116.       Begin Menu MRThreshold 
  117.          Caption         =   "&RThreshold..."
  118.       End
  119.       Begin Menu MSThreshold 
  120.          Caption         =   "&SThreshold..."
  121.       End
  122.       Begin Menu MParRep 
  123.          Caption         =   "P&arityReplace..."
  124.       End
  125.       Begin Menu MDTREnable 
  126.          Caption         =   "&DTREnable"
  127.       End
  128.       Begin Menu Bar3 
  129.          Caption         =   "-"
  130.       End
  131.       Begin Menu MHCD 
  132.          Caption         =   "&CDHolding..."
  133.       End
  134.       Begin Menu MHCTS 
  135.          Caption         =   "CTSH&olding..."
  136.       End
  137.       Begin Menu MHDSR 
  138.          Caption         =   "DSRHo&lding..."
  139.       End
  140.    End
  141. End
  142. '--------------------------------------------------
  143. ' VBTerm - Demonstration program for the MSComm
  144. ' communications custom control.  Demonstrates the
  145. ' functionality of the control in the context of a
  146. ' terminal program.
  147. '
  148. ' Copyright (c) 1992, Crescent Software, Inc.
  149. ' by Don Malin and Carl Franklin.
  150. '--------------------------------------------------
  151. DefInt A-Z
  152.  
  153. Option Explicit
  154.                         
  155. Dim Ret                 'Scratch integer
  156. Dim Temp$               'Scratch string
  157. Dim hLogFile            'Handle of open log file
  158.  
  159. Sub Form_Resize ()
  160.    
  161.    '--- Resize the Term (display) control and
  162.    '    status bar.
  163.    Line1.X2 = ScaleWidth
  164.    Term.Move 0, Line1.Y2 + 15, ScaleWidth, ScaleHeight - Line1.Y2 + 15
  165.    
  166. End Sub
  167.  
  168. Sub Form_Unload (Cancel As Integer)
  169.     Dim T&
  170.  
  171.     If MSComm1.PortOpen Then
  172.        '--- Wait 10 seconds for data to be transmitted
  173.        T& = Timer + 10
  174.        Do While MSComm1.OutBufferCount
  175.           Ret = DoEvents()
  176.           If Timer > T& Then
  177.              Select Case MsgBox("Data cannot be sent", 34)
  178.                 '--- Abort
  179.                 Case 3
  180.                    Cancel = True
  181.                    Exit Sub
  182.                 '--- Retry
  183.                 Case 4
  184.                    T& = Timer + 10
  185.                 '--- Ignore
  186.                 Case 5
  187.                    Exit Do
  188.              End Select
  189.           End If
  190.        Loop
  191.  
  192.        MSComm1.PortOpen = 0
  193.     End If
  194.  
  195.     '--- If log file is open, flush and close it
  196.     If hLogFile Then MCloseLog_Click
  197.  
  198.     End
  199.  
  200. End Sub
  201.  
  202. Sub MCloseLog_Click ()
  203.  
  204.    '--- Close the log file.
  205.    Close hLogFile
  206.    hLogFile = 0
  207.    MOpenLog.Enabled = True
  208.    MCloseLog.Enabled = False
  209.    Form1.Caption = "MSComm Terminal"
  210.  
  211. End Sub
  212.  
  213. Sub MDial_Click ()
  214.     On Local Error Resume Next
  215.     Static Num$
  216.     
  217.     '--- Get a number from the user.
  218.     Num$ = InputBox$("Enter Phone Number:", "Dial Number", Num$)
  219.     If Num$ = "" Then Exit Sub
  220.     
  221.     '--- Open the port if it isn't already
  222.     If Not MSComm1.PortOpen Then
  223.        MOpen_Click
  224.        If Err Then Exit Sub
  225.     End If
  226.     
  227.     '--- Dial the number
  228.     MSComm1.Output = "ATDT" + Num$ + Chr$(13) + Chr$(10)
  229.  
  230. End Sub
  231.  
  232. '--- Toggle DTREnabled property
  233. '
  234. Sub MDTREnable_Click ()
  235.     
  236.     MSComm1.DTREnable = Not MSComm1.DTREnable
  237.     MDTREnable.Checked = MSComm1.DTREnable
  238.  
  239. End Sub
  240.  
  241. Sub MFileExit_Click ()
  242.     
  243.     '--- Use Form_Unload since it has code to check
  244.     '    for un sent data and open log file
  245.     Form_Unload Ret
  246.  
  247. End Sub
  248.  
  249. '--- Toggle DTREnable to hang up the line
  250. '
  251. Sub MHangup_Click ()
  252.  
  253.     Ret = MSComm1.DTREnable     'Save current setting
  254.     MSComm1.DTREnable = True    'Turn DTR on
  255.     MSComm1.DTREnable = False   'Turn DTR off
  256.     MSComm1.DTREnable = Ret     'Restore old setting
  257.  
  258. End Sub
  259.  
  260. '--- Display the value of the CDHolding property.
  261. '
  262. Sub MHCD_Click ()
  263.     
  264.     If MSComm1.CDHolding Then
  265.         Temp$ = "True"
  266.     Else
  267.         Temp$ = "False"
  268.     End If
  269.     MsgBox "CDHolding = " + Temp$
  270.  
  271. End Sub
  272.  
  273. '--- Display the value of the CTSHolding property.
  274. '
  275. Sub MHCTS_Click ()
  276.     
  277.     If MSComm1.CTSHolding Then
  278.         Temp$ = "True"
  279.     Else
  280.         Temp$ = "False"
  281.     End If
  282.     MsgBox "CTSHolding = " + Temp$
  283.  
  284. End Sub
  285.  
  286. '--- Display the value of the DSRHolding property.
  287. '
  288. Sub MHDSR_Click ()
  289.     
  290.     If MSComm1.DSRHolding Then
  291.         Temp$ = "True"
  292.     Else
  293.         Temp$ = "False"
  294.     End If
  295.     MsgBox "DSRHolding = " + Temp$
  296.  
  297. End Sub
  298.  
  299. '*************************************************
  300. 'Sets the InputLen property. The InputLen property
  301. 'determines how many bytes of data are read each
  302. 'time Input is used to retreive data from the
  303. 'input buffer. Setting InputLen to 0 specifies that
  304. 'the entire contents of the buffer should br read.
  305. '*************************************************
  306. '
  307. Sub MInputLen_Click ()
  308.     On Error Resume Next
  309.  
  310.     Temp$ = InputBox$("Enter New InputLen:", "InputLen", Str$(MSComm1.InputLen))
  311.     If Len(Temp$) Then
  312.         MSComm1.InputLen = Val(Temp$)
  313.         If Err Then MsgBox Error$, 48
  314.     End If
  315.  
  316. End Sub
  317.  
  318. '--- Toggles the state of the port (open or closed).
  319. '
  320. Sub MOpen_Click ()
  321.     On Error Resume Next
  322.     Dim OpenFlag
  323.  
  324.     MSComm1.PortOpen = Not MSComm1.PortOpen
  325.     If Err Then MsgBox Error$, 48
  326.     
  327.     OpenFlag = MSComm1.PortOpen
  328.     MOpen.Checked = OpenFlag
  329.     MSendText.Enabled = OpenFlag
  330.     MHangup.Enabled = OpenFlag
  331.     
  332. End Sub
  333.  
  334. Sub MOpenLog_Click ()
  335.    Dim replace
  336.    On Error Resume Next
  337.    
  338.    '--- Get Log File name from the user
  339.    OpenLog.DialogTitle = "Open Communications Log File"
  340.    OpenLog.Filter = "Log Files (*.LOG)|*.log|All Files (*.*)|*.*"
  341.    
  342.    Do
  343.       OpenLog.Filename = ""
  344.       OpenLog.Action = 1
  345.       If Err = CDERR_CANCEL Then Exit Sub
  346.       Temp$ = OpenLog.Filename
  347.  
  348.       '--- If file already exists, do they want to
  349.       '    overwrite or add to it.
  350.       Ret = Len(Dir$(Temp$))
  351.       If Err Then
  352.          MsgBox Error$, 48
  353.          Exit Sub
  354.       End If
  355.       If Ret Then
  356.          replace = MsgBox("Replace existing file - " + Temp$ + "?", 35)
  357.       Else
  358.          replace = 0
  359.       End If
  360.    Loop While replace = 2
  361.  
  362.    '--- User picked "Yes" button - Delete file.
  363.    If replace = 6 Then
  364.       Kill Temp$
  365.       If Err Then
  366.          MsgBox Error$, 48
  367.          Exit Sub
  368.       End If
  369.    End If
  370.  
  371.    '--- Open the log file
  372.    hLogFile = FreeFile
  373.    Open Temp$ For Binary Access Write As hLogFile
  374.    If Err Then
  375.       MsgBox Error$, 48
  376.       Close hLogFile
  377.       hLogFile = 0
  378.       Exit Sub
  379.    Else
  380.       '--- Seek to the end so we append new data
  381.       Seek hLogFile, LOF(hLogFile) + 1
  382.    End If
  383.  
  384.    Form1.Caption = "MSComm Terminal - " + OpenLog.Filetitle
  385.    MOpenLog.Enabled = False
  386.    MCloseLog.Enabled = True
  387.  
  388. End Sub
  389.  
  390. '*************************************************
  391. 'Sets the ParityReplace property. The
  392. 'ParityReplace property holds the character that
  393. 'will replace any incorrect characters that are
  394. 'received due to a parity error.
  395. '*************************************************
  396. '
  397. Sub MParRep_Click ()
  398.     On Error Resume Next
  399.  
  400.     Temp$ = InputBox$("Enter Replace Character", "ParityReplace", Form1.MSComm1.ParityReplace)
  401.     Form1.MSComm1.ParityReplace = Left$(Temp$, 1)
  402.     If Err Then MsgBox Error$, 48
  403.  
  404. End Sub
  405.  
  406. '*************************************************
  407. 'Sets the RThreshold property.  The RThreshold
  408. 'property determines how many bytes can arrive at
  409. 'the receive buffer before the OnComm event is
  410. 'triggered and the CommEvent property is set to
  411. 'MSCOMM_EV_RECEIVE
  412. '*************************************************
  413. '
  414. Sub MRThreshold_Click ()
  415.     On Error Resume Next
  416.  
  417.     Temp$ = InputBox$("Enter New RThreshold:", "RThreshold", Str$(MSComm1.RThreshold))
  418.     If Len(Temp$) Then
  419.         MSComm1.RThreshold = Val(Temp$)
  420.         If Err Then MsgBox Error$, 48
  421.     End If
  422.  
  423. End Sub
  424.  
  425. '*************************************************
  426. 'The OnComm event is used for trapping
  427. 'communications events and errors.
  428. '*************************************************
  429. '
  430. Static Sub MSComm1_OnComm ()
  431.     Dim EVMsg$
  432.     Dim ERMsg$
  433.     
  434.     '--- Branch according to the CommEvent Prop..
  435.     Select Case MSComm1.CommEvent
  436.         '--- Event messages
  437.         Case MSCOMM_EV_RECEIVE
  438.             ShowData Term, (MSComm1.Input)
  439.         Case MSCOMM_EV_SEND
  440.             
  441.         Case MSCOMM_EV_CTS
  442.             EVMsg$ = "Change in CTS Detected"
  443.         Case MSCOMM_EV_DSR
  444.             EVMsg$ = "Change in DSR Detected"
  445.         Case MSCOMM_EV_CD
  446.             EVMsg$ = "Change in CD Detected"
  447.         Case MSCOMM_EV_RING
  448.             EVMsg$ = "The Phone is Ringing"
  449.         Case MSCOMM_EV_EOF
  450.             EVMsg$ = "End of File Detected"
  451.  
  452.         '--- Error messages
  453.         Case MSCOMM_ER_BREAK
  454.             EVMsg$ = "Break Received"
  455.         Case MSCOMM_ER_CTSTO
  456.             ERMsg$ = "CTS Timeout"
  457.         Case MSCOMM_ER_DSRTO
  458.             ERMsg$ = "DSR Timeout"
  459.         Case MSCOMM_ER_FRAME
  460.             EVMsg$ = "Framing Error"
  461.         Case MSCOMM_ER_OVERRUN
  462.             ERMsg$ = "Overrun Error"
  463.         Case MSCOMM_ER_CDTO
  464.             ERMsg$ = "Carrier Detect Timeout"
  465.         Case MSCOMM_ER_RXOVER
  466.             ERMsg$ = "Receive Buffer Overflow"
  467.         Case MSCOMM_ER_RXPARITY
  468.             EVMsg$ = "Parity Error"
  469.         Case MSCOMM_ER_TXFULL
  470.             ERMsg$ = "Transmit Buffer Full"
  471.         Case Else
  472.             ERMsg$ = "Unknown error or event"
  473.     End Select
  474.     
  475.     If Len(EVMsg$) Then
  476.         '--- Display event messages in label
  477.         Label1.Caption = EVMsg$
  478.         EVMsg$ = ""
  479.     ElseIf Len(ERMsg$) Then
  480.         '--- Display error messages in an alert
  481.         '    message box.
  482.         Beep
  483.         Ret = MsgBox(ERMsg$, 1, "Press Cancel to Quit, Ok to ignore.")
  484.         ERMsg$ = ""
  485.         '--- If Cancel (2) was pressed
  486.         If Ret = 2 Then
  487.             MSComm1.PortOpen = 0    'Close the port and quit
  488.         End If
  489.     End If
  490.  
  491. End Sub
  492.  
  493. Sub MSendText_Click ()
  494.    On Error Resume Next
  495.    Dim hSend, BSize, LF&
  496.    
  497.    MSendText.Enabled = False
  498.    
  499.    '--- Get Text File name from the user
  500.    OpenLog.DialogTitle = "Send Text File"
  501.    OpenLog.Filter = "Text Files (*.TXT)|*.txt|All Files (*.*)|*.*"
  502.    Do
  503.       OpenLog.Filename = ""
  504.       OpenLog.Action = 1
  505.       If Err = CDERR_CANCEL Then Exit Sub
  506.       Temp$ = OpenLog.Filename
  507.  
  508.       '--- If file doesn't exist, go back
  509.       Ret = Len(Dir$(Temp$))
  510.       If Err Then
  511.          MsgBox Error$, 48
  512.          MSendText.Enabled = True
  513.          Exit Sub
  514.       End If
  515.       If Ret Then
  516.          Exit Do
  517.       Else
  518.          MsgBox Temp$ + " not found!", 48
  519.       End If
  520.    Loop
  521.  
  522.    '--- Open the log file
  523.    hSend = FreeFile
  524.    Open Temp$ For Binary Access Read As hSend
  525.    If Err Then
  526.       MsgBox Error$, 48
  527.    Else
  528.       '--- Display the Cancel dialog box
  529.       CancelSend = False
  530.       Form2.Label1.Caption = "Transmitting Text File - " + Temp$
  531.       Form2.Show
  532.       
  533.       '--- Read the file in blocks the size of our
  534.       '    transmit buffer.
  535.       BSize = MSComm1.OutBufferSize
  536.       LF& = LOF(hSend)
  537.       Do Until EOF(hSend) Or CancelSend
  538.          '--- Don't read too much at the end
  539.          If LF& - Loc(hSend) <= BSize Then
  540.             BSize = LF& - Loc(hSend) + 1
  541.          End If
  542.       
  543.          '--- Read a block of data
  544.          Temp$ = Space$(BSize)
  545.          Get hSend, , Temp$
  546.       
  547.          '--- Transmit the block
  548.          MSComm1.Output = Temp$
  549.          If Err Then
  550.             MsgBox Error$, 48
  551.             Exit Do
  552.          End If
  553.       
  554.          '--- Wait for all the data to be sent
  555.          Do
  556.             Ret = DoEvents()
  557.          Loop Until MSComm1.OutBufferCount = 0 Or CancelSend
  558.       Loop
  559.    End If
  560.    
  561.    Close hSend
  562.    MSendText.Enabled = True
  563.    CancelSend = True
  564.    Form2.Hide
  565.  
  566. End Sub
  567.  
  568. Sub MSettings_Click ()
  569.     
  570.     '--- Show the communications settings form
  571.     ConfigScrn.Show
  572.  
  573. End Sub
  574.  
  575. '*************************************************
  576. 'Sets the SThreshold property. The SThreshold
  577. 'property determines how many characters (at most)
  578. 'have to be waiting in the output buffer before
  579. 'the CommEvent property is set to EV_SEND and the
  580. 'OnComm event is triggered.
  581. '*************************************************
  582. '
  583. Sub MSThreshold_Click ()
  584.     On Error Resume Next
  585.     
  586.     Temp$ = InputBox$("Enter New SThreshold Value", "SThreshold", Str$(MSComm1.SThreshold))
  587.     If Len(Temp$) Then
  588.         MSComm1.SThreshold = Val(Temp$)
  589.         If Err Then MsgBox Error$, 48
  590.     End If
  591.  
  592. End Sub
  593.  
  594. '**************************************************
  595. 'Adds data to the Term control's .Text property.
  596. 'Also filters control characters such as Back Space
  597. 'Charriage Return and Line Feed, and writes data to
  598. 'an open log file.
  599. '
  600. 'Back Space chars. delete the character to the left,
  601. 'either in the .Text property, or the passed string.
  602. 'Line Feed characters are appended to all Charriage
  603. 'Returns.  The size of the Term control's Text
  604. 'property is also monitored so that it never
  605. 'excedes 16384 characters.
  606. '**************************************************
  607. '
  608. Static Sub ShowData (Term As Control, Dta$)
  609.     On Error Resume Next
  610.     Dim Nd, I
  611.  
  612.     '--- Make sure the existing text doesn't get
  613.     '    too large.
  614.     Nd = Len(Term.Text)
  615.     If Nd >= 16384 Then
  616.        Term.Text = Mid$(Term.Text, 4097)
  617.        Nd = Len(Term.Text)
  618.     End If
  619.  
  620.     '--- Point to the end of Term's data
  621.     Term.SelStart = Nd
  622.  
  623.     '--- Filter/handle Back Space characters
  624.     Do
  625.        I = InStr(Dta$, Chr$(8))
  626.        If I Then
  627.           If I = 1 Then
  628.              Term.SelStart = Nd - 1
  629.              Term.SelLength = 1
  630.              Dta$ = Mid$(Dta$, I + 1)
  631.           Else
  632.              Dta$ = Left$(Dta$, I - 2) + Mid$(Dta$, I + 1)
  633.           End If
  634.        End If
  635.     Loop While I
  636.  
  637.     '--- Elliminate Line Feeds (put back below)
  638.     Do
  639.        I = InStr(Dta$, Chr$(10))
  640.        If I Then
  641.           Dta$ = Left$(Dta$, I - 1) + Mid$(Dta$, I + 1)
  642.        End If
  643.     Loop While I
  644.  
  645.     '--- Make sure all Charriage Returns have a
  646.     '    Line Feed
  647.     I = 1
  648.     Do
  649.        I = InStr(I, Dta$, Chr$(13))
  650.        If I Then
  651.           Dta$ = Left$(Dta$, I) + Chr$(10) + Mid$(Dta$, I + 1)
  652.           I = I + 1
  653.        End If
  654.     Loop While I
  655.  
  656.     '--- Add the filtered data to .Text
  657.     Term.SelText = Dta$
  658.  
  659.     '--- Log data to file if requested
  660.     If hLogFile Then
  661.        I = 2
  662.        Do
  663.           Err = 0
  664.           Put hLogFile, , Dta$
  665.           If Err Then
  666.              I = MsgBox(Error$, 21)
  667.              If I = 2 Then
  668.                 MCloseLog_Click
  669.              End If
  670.           End If
  671.        Loop While I <> 2
  672.     End If
  673.  
  674. End Sub
  675.  
  676. '*************************************************
  677. 'Key strokes trapped here are sent to the Comm
  678. 'control where they are echoed back via the
  679. 'OnComm/MSCOMM_EV_RECEIVE event, and displayed
  680. 'through the ShowData procedure.
  681. '*************************************************
  682. '
  683. Sub Term_KeyPress (KeyAscii As Integer)
  684.     
  685.     '--- If the port is openned,
  686.     If MSComm1.PortOpen Then
  687.        '--- Send the key stroke to the port
  688.        MSComm1.Output = Chr$(KeyAscii)
  689.        '--- Unless Echo is on, there is no need to
  690.        '    let the Text control display the key.
  691.        If Not Echo Then KeyAscii = 0
  692.     End If
  693.  
  694. End Sub
  695.  
  696.