home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / EXTRAS / WINWAIS / VB / DIAL.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1993-12-07  |  20.8 KB  |  644 lines

  1. VERSION 2.00
  2. Begin Form dial_form 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "SLIP Dialer"
  6.    ClientHeight    =   2940
  7.    ClientLeft      =   1005
  8.    ClientTop       =   2370
  9.    ClientWidth     =   7350
  10.    ClipControls    =   0   'False
  11.    ControlBox      =   0   'False
  12.    FontBold        =   0   'False
  13.    FontItalic      =   0   'False
  14.    FontName        =   "MS Sans Serif"
  15.    FontSize        =   8.25
  16.    FontStrikethru  =   0   'False
  17.    FontUnderline   =   0   'False
  18.    Height          =   3345
  19.    Icon            =   DIAL.FRX:0000
  20.    Left            =   945
  21.    LinkTopic       =   "Form1"
  22.    MaxButton       =   0   'False
  23.    MinButton       =   0   'False
  24.    ScaleHeight     =   2940
  25.    ScaleWidth      =   7350
  26.    Top             =   2025
  27.    Width           =   7470
  28.    Begin SSPanel Panel3D8 
  29.       Align           =   1  'Align Top
  30.       Alignment       =   6  'Center - TOP
  31.       BackColor       =   &H00C0C0C0&
  32.       Font3D          =   0  'None
  33.       ForeColor       =   &H00000000&
  34.       Height          =   600
  35.       Left            =   0
  36.       TabIndex        =   22
  37.       Top             =   0
  38.       Width           =   7350
  39.       Begin CommandButton edit_script 
  40.          Caption         =   "Edit"
  41.          Height          =   345
  42.          Left            =   6510
  43.          TabIndex        =   1
  44.          Top             =   150
  45.          Width           =   705
  46.       End
  47.       Begin SSPanel Panel3D9 
  48.          Alignment       =   6  'Center - TOP
  49.          BackColor       =   &H00C0C0C0&
  50.          BevelOuter      =   1  'Inset
  51.          Caption         =   "Select a Script"
  52.          Font3D          =   0  'None
  53.          ForeColor       =   &H00000000&
  54.          Height          =   465
  55.          Left            =   120
  56.          TabIndex        =   24
  57.          Top             =   60
  58.          Width           =   885
  59.       End
  60.       Begin ComboBox dial_script 
  61.          Height          =   300
  62.          Left            =   1050
  63.          Sorted          =   -1  'True
  64.          Style           =   2  'Dropdown List
  65.          TabIndex        =   23
  66.          Top             =   180
  67.          Width           =   5385
  68.       End
  69.    End
  70.    Begin CommandButton done 
  71.       Caption         =   "Done"
  72.       Height          =   345
  73.       Left            =   4740
  74.       TabIndex        =   21
  75.       Top             =   2460
  76.       Width           =   1005
  77.    End
  78.    Begin CommandButton hangup_button 
  79.       Caption         =   "HangUp"
  80.       Height          =   345
  81.       Left            =   3660
  82.       TabIndex        =   20
  83.       Top             =   2460
  84.       Width           =   975
  85.    End
  86.    Begin CommandButton stop_script 
  87.       Caption         =   "Stop"
  88.       Height          =   345
  89.       Left            =   2580
  90.       TabIndex        =   19
  91.       Top             =   2460
  92.       Width           =   975
  93.    End
  94.    Begin CommandButton run_script 
  95.       Caption         =   "Start"
  96.       Height          =   345
  97.       Left            =   1530
  98.       TabIndex        =   18
  99.       Top             =   2460
  100.       Width           =   945
  101.    End
  102.    Begin SSPanel Panel3D3 
  103.       Align           =   1  'Align Top
  104.       BackColor       =   &H00C0C0C0&
  105.       Font3D          =   1  'Raised w/light shading
  106.       ForeColor       =   &H00000000&
  107.       Height          =   540
  108.       Left            =   0
  109.       TabIndex        =   9
  110.       Top             =   600
  111.       Width           =   7350
  112.       Begin SSPanel Panel3D7 
  113.          Alignment       =   1  'Left Justify - MIDDLE
  114.          BackColor       =   &H00C0C0C0&
  115.          BevelOuter      =   1  'Inset
  116.          Caption         =   " Data Bits"
  117.          Font3D          =   0  'None
  118.          ForeColor       =   &H00000000&
  119.          Height          =   345
  120.          Left            =   5760
  121.          TabIndex        =   16
  122.          Top             =   120
  123.          Width           =   1485
  124.          Begin ComboBox databits 
  125.             Height          =   300
  126.             Left            =   900
  127.             Style           =   2  'Dropdown List
  128.             TabIndex        =   17
  129.             Top             =   30
  130.             Width           =   555
  131.          End
  132.       End
  133.       Begin SSPanel Panel3D6 
  134.          Alignment       =   1  'Left Justify - MIDDLE
  135.          BackColor       =   &H00C0C0C0&
  136.          BevelOuter      =   1  'Inset
  137.          Caption         =   " Parity"
  138.          Font3D          =   0  'None
  139.          ForeColor       =   &H00000000&
  140.          Height          =   345
  141.          Left            =   4020
  142.          TabIndex        =   14
  143.          Top             =   120
  144.          Width           =   1515
  145.          Begin ComboBox parity 
  146.             Height          =   300
  147.             Left            =   630
  148.             Style           =   2  'Dropdown List
  149.             TabIndex        =   15
  150.             Top             =   30
  151.             Width           =   855
  152.          End
  153.       End
  154.       Begin SSPanel Panel3D5 
  155.          Alignment       =   1  'Left Justify - MIDDLE
  156.          BackColor       =   &H00C0C0C0&
  157.          BevelOuter      =   1  'Inset
  158.          Caption         =   " Speed"
  159.          Font3D          =   0  'None
  160.          ForeColor       =   &H00000000&
  161.          Height          =   345
  162.          Left            =   2160
  163.          TabIndex        =   12
  164.          Top             =   120
  165.          Width           =   1605
  166.          Begin ComboBox speed 
  167.             Height          =   300
  168.             Left            =   690
  169.             Style           =   2  'Dropdown List
  170.             TabIndex        =   13
  171.             Top             =   30
  172.             Width           =   885
  173.          End
  174.       End
  175.       Begin SSPanel Panel3D4 
  176.          Alignment       =   1  'Left Justify - MIDDLE
  177.          BackColor       =   &H00C0C0C0&
  178.          BevelOuter      =   1  'Inset
  179.          Caption         =   " Com Port"
  180.          Font3D          =   0  'None
  181.          ForeColor       =   &H00000000&
  182.          Height          =   345
  183.          Left            =   150
  184.          TabIndex        =   10
  185.          Top             =   120
  186.          Width           =   1785
  187.          Begin ComboBox commport 
  188.             Height          =   300
  189.             Left            =   900
  190.             Style           =   2  'Dropdown List
  191.             TabIndex        =   11
  192.             Top             =   30
  193.             Width           =   855
  194.          End
  195.       End
  196.    End
  197.    Begin SSPanel Panel3D1 
  198.       Align           =   1  'Align Top
  199.       Alignment       =   0  'Left Justify - TOP
  200.       BackColor       =   &H00C0C0C0&
  201.       Font3D          =   1  'Raised w/light shading
  202.       ForeColor       =   &H00000000&
  203.       Height          =   1245
  204.       Left            =   0
  205.       TabIndex        =   0
  206.       Top             =   1140
  207.       Width           =   7350
  208.       Begin MSComm Comm 
  209.          Interval        =   1000
  210.          Left            =   6780
  211.          Top             =   330
  212.       End
  213.       Begin SSPanel label3 
  214.          Alignment       =   6  'Center - TOP
  215.          BackColor       =   &H00C0C0C0&
  216.          BevelOuter      =   1  'Inset
  217.          Caption         =   "Status"
  218.          Font3D          =   0  'None
  219.          ForeColor       =   &H00000000&
  220.          Height          =   315
  221.          Left            =   150
  222.          TabIndex        =   8
  223.          Top             =   720
  224.          Width           =   885
  225.       End
  226.       Begin SSPanel label2 
  227.          Alignment       =   6  'Center - TOP
  228.          BackColor       =   &H00C0C0C0&
  229.          BevelOuter      =   1  'Inset
  230.          Caption         =   "Reply"
  231.          Font3D          =   0  'None
  232.          ForeColor       =   &H00000000&
  233.          Height          =   255
  234.          Left            =   150
  235.          TabIndex        =   7
  236.          Top             =   420
  237.          Width           =   885
  238.       End
  239.       Begin SSPanel label1 
  240.          Alignment       =   6  'Center - TOP
  241.          BackColor       =   &H00C0C0C0&
  242.          BevelOuter      =   1  'Inset
  243.          Caption         =   "Send"
  244.          Font3D          =   0  'None
  245.          ForeColor       =   &H00000000&
  246.          Height          =   285
  247.          Left            =   150
  248.          TabIndex        =   6
  249.          Top             =   90
  250.          Width           =   885
  251.       End
  252.       Begin SSPanel Panel3D2 
  253.          BackColor       =   &H00C0C0C0&
  254.          BevelOuter      =   1  'Inset
  255.          Font3D          =   1  'Raised w/light shading
  256.          ForeColor       =   &H00000000&
  257.          Height          =   945
  258.          Left            =   1050
  259.          TabIndex        =   2
  260.          Top             =   90
  261.          Width           =   6225
  262.          Begin Label xmit 
  263.             BackColor       =   &H00FFFFFF&
  264.             BorderStyle     =   1  'Fixed Single
  265.             FontBold        =   0   'False
  266.             FontItalic      =   0   'False
  267.             FontName        =   "Terminal"
  268.             FontSize        =   9
  269.             FontStrikethru  =   0   'False
  270.             FontUnderline   =   0   'False
  271.             Height          =   255
  272.             Left            =   30
  273.             TabIndex        =   5
  274.             Top             =   30
  275.             Width           =   6135
  276.          End
  277.          Begin Label recv 
  278.             BackColor       =   &H00FFFFFF&
  279.             BorderStyle     =   1  'Fixed Single
  280.             FontBold        =   0   'False
  281.             FontItalic      =   0   'False
  282.             FontName        =   "Terminal"
  283.             FontSize        =   9
  284.             FontStrikethru  =   0   'False
  285.             FontUnderline   =   0   'False
  286.             Height          =   255
  287.             Left            =   30
  288.             TabIndex        =   4
  289.             Top             =   330
  290.             Width           =   6135
  291.          End
  292.          Begin Label status 
  293.             BackColor       =   &H00FFFFFF&
  294.             BorderStyle     =   1  'Fixed Single
  295.             FontBold        =   0   'False
  296.             FontItalic      =   0   'False
  297.             FontName        =   "Terminal"
  298.             FontSize        =   9
  299.             FontStrikethru  =   0   'False
  300.             FontUnderline   =   0   'False
  301.             Height          =   255
  302.             Left            =   30
  303.             TabIndex        =   3
  304.             Top             =   630
  305.             Width           =   6135
  306.          End
  307.       End
  308.    End
  309.    Begin Timer interval_timer 
  310.       Enabled         =   0   'False
  311.       Interval        =   1
  312.       Left            =   3240
  313.       Top             =   540
  314.    End
  315. Dim time_expired As Integer
  316. Dim recv_matched As Integer
  317. Dim rcv As String
  318. Dim do_capture As Integer
  319. Dim captured As String
  320. Dim cancel_script As Integer
  321. Dim init_file As String
  322. Dim init_section As String
  323. '---------------------------------------
  324. 'Comm Control
  325. '---------------------------------------
  326. 'Handshaking
  327. Const MSCOMM_HANDSHAKE_NONE = 0
  328. Const MSCOMM_HANDSHAKE_XONXOFF = 1
  329. Const MSCOMM_HANDSHAKE_RTS = 2
  330. Const MSCOMM_HANDSHAKE_RTSXONXOFF = 3
  331. 'Event constants
  332. Const MSCOMM_EV_SEND = 1
  333. Const MSCOMM_EV_RECEIVE = 2
  334. Const MSCOMM_EV_CTS = 3
  335. Const MSCOMM_EV_DSR = 4
  336. Const MSCOMM_EV_CD = 5
  337. Const MSCOMM_EV_RING = 6
  338. Const MSCOMM_EV_EOF = 7
  339. 'Error code constants
  340. Const MSCOMM_ER_BREAK = 1001
  341. Const MSCOMM_ER_CTSTO = 1002
  342. Const MSCOMM_ER_DSRTO = 1003
  343. Const MSCOMM_ER_FRAME = 1004
  344. Const MSCOMM_ER_OVERRUN = 1006
  345. Const MSCOMM_ER_CDTO = 1007
  346. Const MSCOMM_ER_RXOVER = 1008
  347. Const MSCOMM_ER_RXPARITY = 1009
  348. Const MSCOMM_ER_TXFULL = 1010
  349. Declare Function GetINIInt Lib "kernel" Alias "GetPrivateProfileInt" (ByVal app As String, ByVal key As String, ByVal def As Integer, ByVal fn As String) As Integer
  350. Declare Function GetINIString Lib "kernel" Alias "GetPrivateProfileString" (ByVal app As String, ByVal key As String, ByVal def As String, ByVal ret As String, ByVal retsz As Integer, ByVal fn As String) As Integer
  351. Declare Function PutINIString Lib "kernel" Alias "WritePrivateProfileString" (ByVal app As String, ByVal key As String, ByVal arg As Any, ByVal fn As String) As Integer
  352. Sub done_click ()
  353.   End
  354. End Sub
  355. Sub edit_script_Click ()
  356.   z = Shell("notepad " + dial_script.Text + ".slp", 1)
  357. End Sub
  358. Sub Form_Load ()
  359.   CommPort.AddItem "COM1"
  360.   CommPort.AddItem "COM2"
  361.   CommPort.AddItem "COM3"
  362.   CommPort.AddItem "COM4"
  363.   parity.AddItem "EVEN"
  364.   parity.AddItem "ODD"
  365.   parity.AddItem "NONE"
  366.   parity.AddItem "MARK"
  367.   parity.AddItem "SPACE"
  368.   speed.AddItem "300"
  369.   speed.AddItem "1200"
  370.   speed.AddItem "2400"
  371.   speed.AddItem "9600"
  372.   speed.AddItem "19200"
  373.   databits.AddItem "8"
  374.   databits.AddItem "7"
  375.   parity.ListIndex = GetINIInt("Slip", "Parity", 0, "wais.ini")
  376.   CommPort.ListIndex = GetINIInt("Slip", "Port", 0, "wais.ini")
  377.   speed.ListIndex = GetINIInt("Slip", "Speed", 0, "wais.ini")
  378.   databits.ListIndex = GetINIInt("Slip", "DataBits", 0, "wais.ini")
  379.   If comm.PortOpen = True Then
  380.     run_script.Enabled = False
  381.     stop_script.Enabled = False
  382.     hangup_button.Enabled = True
  383.   Else
  384.     run_script.Enabled = True
  385.     stop_script.Enabled = False
  386.     hangup_button.Enabled = False
  387.   End If
  388.   dial_script.Clear
  389.   sc$ = Dir$("*.slp")
  390.   While sc$ <> ""
  391.     sc$ = Left$(sc$, InStr(sc$, ".") - 1)
  392.     dial_script.AddItem sc$
  393.     sc$ = Dir$
  394.   Wend
  395.   dial_script.ListIndex = 0
  396. End Sub
  397. Sub Form_Unload (cancel As Integer)
  398.   If cancel Then
  399.     If comm.PortOpen = True Then
  400.       comm.PortOpen = False
  401.     End If
  402.   End If
  403.   End
  404. End Sub
  405. Sub hangup_button_Click ()
  406.   If comm.PortOpen = True Then
  407.     comm.PortOpen = False
  408.   End If
  409.   run_script.Enabled = True
  410.   stop_script.Enabled = False
  411.   hangup_button.Enabled = False
  412. End Sub
  413. Sub interval_timer_Timer ()
  414.     If arg = "" Then
  415.       recv_matched = True
  416.     Else
  417.       time_expired = True
  418.     End If
  419. End Sub
  420. Sub process_script ()
  421. Dim op1 As Integer
  422. Dim op2 As Integer
  423. Dim ln As String
  424. Dim ch As String
  425. Dim comd As String
  426.   label1.Refresh
  427.   label2.Refresh
  428.   label3.Refresh
  429.   z = PutINIString("Slip", "Parity", Str$(parity.ListIndex), "wais.ini")
  430.   z = PutINIString("Slip", "Speed", Str$(speed.ListIndex), "wais.ini")
  431.   z = PutINIString("Slip", "Port", Str$(CommPort.ListIndex), "wais.ini")
  432.   z = PutINIString("Slip", "DataBits", Str$(databits.ListIndex), "wais.ini")
  433.   comm.CommPort = Val(Right$(CommPort.List(CommPort.ListIndex), 1))
  434.   cs$ = speed.List(speed.ListIndex) + ","
  435.   cs$ = cs$ + Left$(parity.List(parity.ListIndex), 1) + ","
  436.   cs$ = cs$ + databits.List(databits.ListIndex) + "," + "1"
  437.   comm.Settings = cs$
  438.           
  439.   comm.InputLen = 1
  440.   comm.PortOpen = True
  441.   run_script.Enabled = False
  442.   stop_script.Enabled = True
  443.   done.Enabled = False
  444.   script_handle = FreeFile
  445.   Open dial_script.Text + ".slp" For Input As script_handle
  446.   Do While Not EOF(script_handle)
  447.       
  448.     Line Input #script_handle, ln
  449.     ln = Trim$(ln)
  450.     c = InStr(ln, "#")
  451.     If c > 0 Then
  452.       ln = Left$(ln, c - 1)
  453.     End If
  454.     If Len(ln) > 0 Then
  455.       op1 = InStr(ln, " ")
  456.       If op1 = 0 Then
  457.         MsgBox "Command " + ln + " has no operands", MB_INFO
  458.         Exit Do
  459.       End If
  460.       
  461.       comd = LCase$(Left$(ln, op1 - 1))
  462.       
  463.       Select Case comd
  464.         Case "file"
  465.           init_file = Trim$(Right$(ln, Len(ln) - op1)) + ".ini"
  466.             
  467.         Case "section"
  468.           init_section = Trim$(Right$(ln, Len(ln) - op1))
  469.             
  470.         Case "set"
  471.           If init_file = "" Or init_section = "" Then
  472.             MsgBox "Missing INI file name or section", MB_INFO
  473.             Close (slip_handle)
  474.             comm.PortOpen = False
  475.             End
  476.           End If
  477.           op2 = InStr(ln, "=")
  478.           cmd$ = Trim$(Mid$(ln, op1, op2 - op1))
  479.           cmdval$ = Right$(ln, Len(ln) - op2)
  480.             
  481.           Select Case cmdval$
  482.             Case "capture"
  483.               z = PutINIString(init_section, cmd$, captured, init_file)
  484.             Case "port"
  485.               z = PutINIString(init_section, cmd$, Str$(CommPort.ListIndex + 1), init_file)
  486.             Case "speed"
  487.               txt$ = speed.Text
  488.               z = PutINIString(init_section, cmd$, txt$, init_file)
  489.             Case Else
  490.               z = PutINIString(init_section, cmd$, cmdval$, init_file)
  491.           End Select
  492.           
  493.         Case "send", "prompt"
  494.           GoSub get_time_and_arg
  495.           If comd = "prompt" Then
  496.             prompt_form.prompt.Caption = arg
  497.             prompt_form.Show 1
  498.             Unload prompt_form
  499.           End If
  500.           status.Caption = "Sending output"
  501.           status.Refresh
  502.           xmit.Caption = ""
  503.           xmit.Refresh
  504.           For x = 1 To Len(arg)
  505.             ch = Mid$(arg, x, 1)
  506.             If ch = "^" Then
  507.               xmit.Caption = xmit.Caption + ch
  508.               x = x + 1
  509.               ch = Chr$(Asc(Mid$(arg, x, 1)) And &H3F)
  510.             End If
  511.             comm.Output = ch
  512.             If comd = "prompt" Then
  513.               xmit.Caption = xmit.Caption + "*"
  514.             Else
  515.               xmit.Caption = xmit.Caption + ch
  516.             End If
  517.             If Len(xmit.Caption) > 50 Then
  518.               xmit.Caption = Right$(xmit.Caption, 50)
  519.             End If
  520.             xmit.Refresh
  521.           Next x
  522.         
  523.         Case "wait", "capture"
  524.           Debug.Print ln
  525.           GoSub get_time_and_arg
  526.           If comd = "capture" Then
  527.             do_capture = True
  528.             captured = ""
  529.           Else
  530.             do_capture = False
  531.           End If
  532.          
  533.           status.Caption = "Waiting" + Str$(time_to_wait) + " seconds"
  534.           If arg <> "" Then
  535.             status.Caption = status.Caption + " for: " + arg
  536.             If InStr(arg, "^") > 0 Then
  537.               tmp$ = ""
  538.               For x = 1 To Len(arg)
  539.                 If Mid$(arg, x, 1) = "^" Then
  540.                   ctrlc = True
  541.                 Else
  542.                   If ctrlc = True Then
  543.                     tmp$ = tmp$ + Chr$(Asc(Mid$(arg, x, 1)) And &H3F)
  544.                     ctrlc = False
  545.                   Else
  546.                     tmp$ = tmp$ + Mid$(arg, x, 1)
  547.                   End If
  548.                 End If
  549.               Next x
  550.               arg = tmp$
  551.             End If
  552.           End If
  553.           status.Refresh
  554.           recv.Caption = ""
  555.           recv.Refresh
  556.           
  557.           time_expired = False
  558.           recv_matched = False
  559.           cancel_script = False
  560.           
  561.           interval_timer.Interval = time_to_wait * 1000
  562.           interval_timer.Enabled = True
  563.           
  564.           'char_timer.Enabled = True
  565.           
  566.           Do While time_expired = False And recv_matched = False And cancel_script = False
  567.             z = DoEvents()
  568.             If comm.PortOpen = False Then
  569.               Exit Do
  570.             End If
  571.             ch = comm.Input
  572.             If Len(ch) > 0 Then
  573.               If do_capture = True Then
  574.                 captured = captured + ch
  575.               End If
  576.               rcv = rcv + ch
  577.               If Len(rcv) > Len(arg) Then
  578.                 rcv = Right$(rcv, Len(arg))
  579.               End If
  580.               recv.Caption = recv.Caption + ch
  581.               If Len(recv.Caption) > 50 Then
  582.                 recv.Caption = Right$(recv.Caption, 50)
  583.               End If
  584.               If arg <> "" And rcv = arg Then
  585.                 recv_matched = True
  586.                 If do_capture = True Then
  587.                   captured = Left$(captured, Len(captured) - Len(arg))
  588.                 End If
  589.               End If
  590.               If Asc(ch) < 32 Then
  591.                 recv.Caption = ""
  592.               End If
  593.             End If
  594.           Loop
  595.           
  596.           'char_timer.Enabled = False
  597.           interval_timer.Enabled = False
  598.           
  599.           If time_expired Then
  600.             MsgBox "Time expired", MB_INFO
  601.             Close (slip_handle)
  602.             comm.PortOpen = False
  603.             End
  604.           End If
  605.           If cancel_script Then
  606.             Close (slip_handle)
  607.             If comm.PortOpen = True Then
  608.               comm.PortOpen = False
  609.             End If
  610.             run_script.Enabled = True
  611.             stop_script.Enabled = False
  612.             done.Enabled = True
  613.             Exit Do
  614.           End If
  615.         Case Else
  616.           MsgBox "Unrecognized command: " + comd$, MB_INFO
  617.       End Select
  618.     End If
  619.   Loop
  620.   Close (slip_handle)
  621.   ' leave the line connected
  622.   Exit Sub
  623. get_time_and_arg:
  624.         
  625.   time_to_wait = Val(Right$(ln, Len(ln) - op1))
  626.   op1 = InStr(ln, Chr$(34))
  627.   If op1 = 0 Then
  628.     arg = ""
  629.   Else
  630.     op2 = InStr(op1 + 1, ln, Chr$(34))
  631.     arg = Mid$(ln, op1 + 1, op2 - op1 - 1)
  632.   End If
  633.   Return
  634. End Sub
  635. Sub run_script_Click ()
  636.   process_script
  637.   If cancel_script = False Then
  638.     End
  639.   End If
  640. End Sub
  641. Sub stop_script_Click ()
  642.   cancel_script = True
  643. End Sub
  644.