home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / update / crescent / mwupd / mwmodem.frm (.txt) next >
Encoding:
Visual Basic Form  |  1994-10-17  |  20.2 KB  |  617 lines

  1. VERSION 2.00
  2. Begin Form MWModem 
  3.    BorderStyle     =   3  'Fixed Double
  4.    Caption         =   "Modem Database"
  5.    ClientHeight    =   2616
  6.    ClientLeft      =   648
  7.    ClientTop       =   2268
  8.    ClientWidth     =   6720
  9.    Height          =   3264
  10.    Icon            =   MWMODEM.FRX:0000
  11.    Left            =   600
  12.    LinkTopic       =   "Form2"
  13.    MaxButton       =   0   'False
  14.    ScaleHeight     =   2616
  15.    ScaleWidth      =   6720
  16.    Top             =   1668
  17.    Width           =   6816
  18.    Begin TextBox TbPort 
  19.       Height          =   285
  20.       Left            =   1680
  21.       TabIndex        =   7
  22.       Text            =   "2"
  23.       Top             =   2040
  24.       Width           =   495
  25.    End
  26.    Begin CommandButton BtnOkExit 
  27.       Cancel          =   -1  'True
  28.       Caption         =   "Cancel"
  29.       Height          =   372
  30.       Index           =   1
  31.       Left            =   5520
  32.       TabIndex        =   5
  33.       Top             =   2040
  34.       Width           =   972
  35.    End
  36.    Begin CommandButton BtnOkExit 
  37.       Caption         =   "OK"
  38.       Default         =   -1  'True
  39.       Height          =   375
  40.       Index           =   0
  41.       Left            =   4680
  42.       TabIndex        =   4
  43.       Top             =   2040
  44.       Width           =   735
  45.    End
  46.    Begin ListBox List2 
  47.       Height          =   1560
  48.       Left            =   2160
  49.       TabIndex        =   1
  50.       Top             =   360
  51.       Width           =   4332
  52.    End
  53.    Begin ListBox List1 
  54.       Height          =   1560
  55.       Left            =   240
  56.       Sorted          =   -1  'True
  57.       TabIndex        =   0
  58.       Top             =   360
  59.       Width           =   1812
  60.    End
  61.    Begin Label Label1 
  62.       Alignment       =   1  'Right Justify
  63.       Caption         =   "Comm Port:"
  64.       Height          =   255
  65.       Index           =   2
  66.       Left            =   240
  67.       TabIndex        =   6
  68.       Top             =   2050
  69.       Width           =   1335
  70.    End
  71.    Begin Label Label1 
  72.       Caption         =   "Model:"
  73.       Height          =   252
  74.       Index           =   1
  75.       Left            =   2160
  76.       TabIndex        =   3
  77.       Top             =   120
  78.       Width           =   852
  79.    End
  80.    Begin Label Label1 
  81.       Caption         =   "Make:"
  82.       Height          =   252
  83.       Index           =   0
  84.       Left            =   240
  85.       TabIndex        =   2
  86.       Top             =   120
  87.       Width           =   852
  88.    End
  89.    Begin Menu MenuUtil 
  90.       Caption         =   "&Utilities"
  91.       Begin Menu MUtil 
  92.          Caption         =   "&Edit Settings"
  93.          Index           =   1
  94.       End
  95.       Begin Menu MUtil 
  96.          Caption         =   "&Add Modem"
  97.          Index           =   2
  98.       End
  99.       Begin Menu MUtil 
  100.          Caption         =   "&Delete Modem"
  101.          Index           =   3
  102.       End
  103.       Begin Menu MUtil 
  104.          Caption         =   "-"
  105.          Index           =   4
  106.       End
  107.       Begin Menu MUtil 
  108.          Caption         =   "&Pack Database"
  109.          Index           =   5
  110.       End
  111.    End
  112. Option Explicit
  113. '-- ModemWare Copyright (c) 1992 - 1994 Crescent Software.
  114. '   Written by Carl Franklin with help from and thanks to Bill Conley.
  115. '001 10/17/94 - Fixed bug that caused Modem Number to be set to 1 when
  116. '               adding a new modem to a databse that had deleted modems.
  117. Dim DataFileNum As Integer
  118. Dim CurModemNumber&
  119. Sub BtnOkExit_Click (Index As Integer)
  120. Dim PortNum As Integer, Timeout As Integer, ErrFlag As Integer, C As Integer
  121. Dim Result As Integer, ModemIndex As Integer, Dummy As Integer
  122. Dim OldCap$, T$, SetStr$, InitString$, Temp$, NextCmd$, ConfigFile$, AppName$
  123. Dim OldSettings$, Rec&, HighestBaud&
  124.     OldCap$ = Caption
  125.     If Index Then
  126.     MW_CancelFlag = True
  127.     Tag = ""
  128.     GoTo MWModemExit:
  129.     Else
  130.     InitModemWare
  131.     '-- Find the Modem Number of the selected modem
  132.     T$ = List2.List(List2.ListIndex)
  133.     For Rec& = 1 To MW_NumRecords&
  134.         If MW_ModemInfo(Rec&).ModemName$ = T$ Then
  135.         Exit For
  136.         End If
  137.     Next
  138.     '-- Try to configure the modem.
  139.     On Error Resume Next
  140.     If Trim$(T$) = "Null Modem" Then GoTo MWSaveModemData
  141.     '-- Get InitString
  142.     InitString$ = ZTrim$(MW_ModemInfo(Rec&).InitString)
  143.     '-- Get the port number
  144.     PortNum = Val(TbPort.Text)
  145.     If PortNum = 0 Then
  146.         MsgBox "No Port Specified"
  147.         Exit Sub
  148.     End If
  149.     '-- Get the Settings
  150.     HighestBaud& = MW_ModemInfo(Rec&).HighestBaud
  151.     OldSettings$ = MW_Global_Comm1.Settings
  152.     If HighestBaud& >= 2400 Then
  153.         SetStr$ = "2400,N,8,1"
  154.     Else
  155.         SetStr$ = "300,N,8,1"
  156.     End If
  157.     MW_Global_Comm1.CommPort = PortNum
  158.     MW_Global_Comm1.Settings = SetStr$
  159.     On Error Resume Next
  160.     MW_Global_Comm1.PortOpen = True
  161.     If Err Then
  162.         MsgBox "COM" & LTrim$(Str$(PortNum)) & " is not available"
  163.         Exit Sub
  164.     End If
  165.     '-- Set an initial Timeout value
  166.     Timeout = 30
  167.     Caption = "Configuring your modem, please wait..."
  168.     ErrFlag = False
  169.     Screen.MousePointer = 11
  170.     Temp$ = RemoveCaret$(ZTrim$(InitString$))
  171.         C = InStr(Temp$, MW_CR$)
  172.         If C Then
  173.         NextCmd$ = ZTrim$(Left$(Temp$, C))
  174.         If Len(Temp$) > C Then
  175.             Temp$ = Mid$(Temp$, C + 1)
  176.         End If
  177.         Else
  178.         Exit Do
  179.         End If
  180. MWTryAgain:
  181.         
  182.         Call SendModemCmd(MW_Global_Comm1, NextCmd$, 1, Timeout, Result)
  183.         Select Case Result
  184.         Case MW_RESULT_OK
  185.             '-- Exit the loop
  186.             Exit Do
  187.         Case MW_RESULT_ERROR, MW_RESULT_TIMEOUT
  188.             If ErrFlag = False Then
  189.             Caption = "An Error occurred, trying again.."
  190.             Timeout = Timeout + 10
  191.             ErrFlag = True
  192.             GoTo MWTryAgain:
  193.             Else
  194.             Caption = OldCap$
  195.             Screen.MousePointer = 0
  196.             MsgBox "Error: You may have picked the wrong modem."
  197.             If MW_Global_Comm1.PortOpen Then MW_Global_Comm1.PortOpen = False
  198.             Exit Sub
  199.             End If
  200.         Case Else
  201.             Caption = OldCap$
  202.             Screen.MousePointer = 0
  203.             MsgBox MWErrorMsg$()
  204.             If MW_Global_Comm1.PortOpen Then MW_Global_Comm1.PortOpen = False
  205.             Exit Sub
  206.         End Select
  207.         
  208.         '-- Pause before trying again
  209.         MWPause 3
  210.     Loop
  211. MWSaveModemData:
  212.     '-- Save info in config file.
  213.     Caption = "Saving Information..."
  214.     '-- Get the configuration INI filename
  215.     ConfigFile$ = GetConfigFileName$()
  216.     AppName$ = "Modem_" & MW_Global_Comm1.Tag
  217.     '-- Get the Modem's Index in the MWCurModem array
  218.     ModemIndex = GetModemIndex(MW_Global_Comm1)
  219.     If ModemIndex = 0 Then
  220.         Stop
  221.     End If
  222.     '-- Save Modem Number
  223.     Temp$ = LTrim$(Str$(MW_ModemInfo(Rec&).ModemNumber))
  224.     Dummy = MWPutConfigString(AppName$, "ModemNumber", Temp$, ConfigFile$)
  225.     MW_CurModem(ModemIndex).ModemNumber = MW_ModemInfo(Rec&).ModemNumber
  226.     '-- Save Modem Name
  227.     Temp$ = ZTrim$(MW_ModemInfo(Rec&).ModemName)
  228.     If Len(Temp$) = 0 Then Temp$ = "Generic 2400 Baud Modem"
  229.     Dummy = MWPutConfigString(AppName$, "ModemName", Temp$, ConfigFile$)
  230.     MW_CurModem(ModemIndex).ModemName = MW_ModemInfo(Rec&).ModemName
  231.     '-- Save Highest Baud rate
  232.     Temp$ = LTrim$(Str$(MW_ModemInfo(Rec&).HighestBaud))
  233.     If Len(Temp$) = 0 Then Temp$ = "2400"
  234.     Dummy = MWPutConfigString(AppName$, "HighestBaud", Temp$, ConfigFile$)
  235.     MW_CurModem(ModemIndex).HighestBaud = MW_ModemInfo(Rec&).HighestBaud
  236.     '-- Save Init String
  237.     Temp$ = ZTrim$(MW_ModemInfo(Rec&).InitString)
  238.     If Len(Temp$) = 0 Then Temp$ = "AT^M"
  239.     Dummy = MWPutConfigString(AppName$, "InitString", Temp$, ConfigFile$)
  240.     MW_CurModem(ModemIndex).InitString = MW_ModemInfo(Rec&).InitString
  241.     '-- Save Connect String
  242.     Temp$ = ZTrim$(MW_ModemInfo(Rec&).Connect)
  243.     If Len(Temp$) = 0 Then Temp$ = "CONNECT"
  244.     Dummy = MWPutConfigString(AppName$, "Connect", Temp$, ConfigFile$)
  245.     MW_CurModem(ModemIndex).Connect = MW_ModemInfo(Rec&).Connect
  246.     '-- Save Attention String
  247.     Temp$ = ZTrim$(MW_ModemInfo(Rec&).Attention)
  248.     If Len(Temp$) = 0 Then Temp$ = "AT"
  249.     Dummy = MWPutConfigString(AppName$, "Attention", Temp$, ConfigFile$)
  250.     MW_CurModem(ModemIndex).Attention = MW_ModemInfo(Rec&).Attention
  251.     '-- Save Hangup String
  252.     Temp$ = ZTrim$(MW_ModemInfo(Rec&).Hangup)
  253.     If Len(Temp$) = 0 Then Temp$ = "ATH^M"
  254.     Dummy = MWPutConfigString(AppName$, "Hangup", Temp$, ConfigFile$)
  255.     MW_CurModem(ModemIndex).Hangup = MW_ModemInfo(Rec&).Hangup
  256.     '-- Save Reset String
  257.     Temp$ = ZTrim$(MW_ModemInfo(Rec&).Reset)
  258.     If Len(Temp$) = 0 Then Temp$ = "ATZ^M"
  259.     Dummy = MWPutConfigString(AppName$, "Reset", Temp$, ConfigFile$)
  260.     MW_CurModem(ModemIndex).Reset = MW_ModemInfo(Rec&).Reset
  261.     '-- Save Answer String
  262.     Temp$ = ZTrim$(MW_ModemInfo(Rec&).Answer)
  263.     If Len(Temp$) = 0 Then Temp$ = "ATA^M"
  264.     Dummy = MWPutConfigString(AppName$, "Answer", Temp$, ConfigFile$)
  265.     MW_CurModem(ModemIndex).Answer = MW_ModemInfo(Rec&).Answer
  266.     '-- Save Dial String
  267.     Temp$ = ZTrim$(MW_ModemInfo(Rec&).Dial)
  268.     If Len(Temp$) = 0 Then Temp$ = "ATDT"
  269.     Dummy = MWPutConfigString(AppName$, "Dial", Temp$, ConfigFile$)
  270.     MW_CurModem(ModemIndex).Dial = MW_ModemInfo(Rec&).Dial
  271.     '-- Save Busy String
  272.     Temp$ = ZTrim$(MW_ModemInfo(Rec&).Busy)
  273.     If Len(Temp$) = 0 Then Temp$ = "BUSY"
  274.     Dummy = MWPutConfigString(AppName$, "Busy", Temp$, ConfigFile$)
  275.     MW_CurModem(ModemIndex).Busy = MW_ModemInfo(Rec&).Busy
  276.     '-- Set the Tag to the port/modem spcecified
  277.     T$ = "COM" & LTrim$(Str$(PortNum)) & ": " & MW_ModemInfo(Rec&).ModemName
  278.     Tag = T$
  279.     End If
  280. MWModemExit:
  281.     If MW_Global_Comm1.PortOpen Then
  282.     MW_Global_Comm1.PortOpen = False
  283.     End If
  284.     Caption = OldCap$
  285.     Screen.MousePointer = 0
  286.     Close DataFileNum
  287.     Hide
  288. End Sub
  289. Sub Form_Activate ()
  290.     TbPort.Text = Str$(MW_Global_Comm1.CommPort)
  291.     BtnOkExit(0).SetFocus
  292.     List1.SetFocus
  293. End Sub
  294. Sub Form_Load ()
  295.     CenterForm Me
  296.     Screen.MousePointer = 11
  297.     LoadModemData
  298.     Screen.MousePointer = 0
  299. End Sub
  300. Sub List1_Click ()
  301. Dim L As Integer, LoPoint As Integer, HiPoint As Integer, LastPoint As Integer
  302. Dim List2Index As Integer
  303. Dim Criteria$, ModemBrand$, Counter&, Match&, CurRecord&, NewRec&
  304.     Criteria$ = UCase$(List1.List(List1.ListIndex))
  305.     '-- Find the first
  306.     CurRecord& = UBound(MW_LinkRecords)
  307.     L = CurRecord& \ 2
  308.     LoPoint = 1: HiPoint = CurRecord&
  309.     Do
  310.     LastPoint = L
  311.     ModemBrand$ = UCase$(Trim$(MW_LinkRecords(L).VendorName))
  312.     Select Case ModemBrand$
  313.         Case Is > Criteria$
  314.         HiPoint = L
  315.         L = LoPoint + ((L - LoPoint) \ 2)
  316.         If L = LastPoint And LastPoint > LoPoint Then L = L - 1
  317.         Case Is < Criteria$
  318.         LoPoint = L
  319.         L = L + ((HiPoint - L) \ 2)
  320.         If L = LastPoint And LastPoint < HiPoint Then L = L + 1
  321.         Case Else
  322.         Exit Do
  323.     End Select
  324.     Loop Until L = LoPoint Or L = HiPoint
  325.     CurRecord& = MW_LinkRecords(L).Record
  326.     '-- Clear the list box
  327.     List2.Clear
  328.     '-- Save record info and put the first modem into List2
  329.     Do
  330.     ModemBrand$ = UCase$(Trim$(MW_ModemInfo(CurRecord&).VendorName))
  331.     If ModemBrand$ = Criteria$ Then
  332.         If MW_ModemInfo(CurRecord&).DeletedFlag = 0 Then
  333.         List2.AddItem MW_ModemInfo(CurRecord&).ModemName
  334.         If MW_ModemInfo(CurRecord&).ModemNumber = CurModemNumber& Then
  335.             List2Index = List2.NewIndex
  336.         End If
  337.         End If
  338.         If MW_ModemInfo(CurRecord&).LinkRecord Then
  339.         CurRecord& = MW_ModemInfo(CurRecord&).LinkRecord
  340.         Else
  341.         CurRecord& = CurRecord& + 1
  342.         If CurRecord& > MW_NumRecords& Then Exit Do
  343.         End If
  344.     Else
  345.         Exit Do
  346.     End If
  347.     Loop
  348.     List2.ListIndex = List2Index
  349. End Sub
  350. Sub List2_DblClick ()
  351.     BtnOkExit(0) = True
  352. End Sub
  353. Sub LoadModemData ()
  354. Dim Dummy As Integer, I As Integer, Linked As Integer, BrandNo As Integer, List1Index As Integer
  355. Dim ConfigFile$, AppName$, Temp$, ModemBrand$, LastBrand$
  356. Dim SrchRec&, Rec&
  357.     If DataFileNum Then
  358.     Close DataFileNum
  359.     DataFileNum = 0
  360.     End If
  361.     List1.Clear
  362.     List2.Clear
  363.     '-- Get the configuration INI filename
  364.     ConfigFile$ = GetConfigFileName$()
  365.     '-- All Modem Settings are listed under "[Modem_<Tag property>]" in the INI file.
  366.     AppName$ = "Modem_" & MW_Global_Comm1.Tag
  367.     '-- Get Modem Number
  368.     Temp$ = Space$(10)
  369.     Dummy = MWGetConfigString(AppName$, "ModemNumber", "", Temp$, 10, ConfigFile$)
  370.     CurModemNumber& = Val(Temp$)
  371.     '-- Open MODEMS.DAT
  372.     DataFile$ = App.Path
  373.     If Right$(DataFile$, 1) = "\" Then
  374.     DataFile$ = DataFile$ & "MODEMS.DAT"
  375.     Else
  376.     DataFile$ = DataFile$ & "\MODEMS.DAT"
  377.     End If
  378.     On Error Resume Next
  379.     DataFileNum = FreeFile
  380.     Open DataFile$ For Binary As DataFileNum
  381.     If Err Then
  382.     MsgBox "Can not find MODEMS.DAT. Please copy it to where your .EXE file is."
  383.     Unload MWModem
  384.     Exit Sub
  385.     End If
  386.     '-- Read the total number of records
  387.     Get #DataFileNum, , MW_NumRecords&
  388.     '-- Grow the array and read the data
  389.     ReDim MW_ModemInfo(1 To MW_NumRecords&) As MW_ModemInfoType
  390.     LastBrand$ = ""
  391.     NumBrands = 0
  392.     Rec& = 1
  393.     For I = 1 To MW_NumRecords&
  394.     Get #DataFileNum, , MW_ModemInfo(Rec&)
  395.     If Not MW_ModemInfo(Rec&).DeletedFlag Then
  396.         ModemBrand$ = Trim$(MW_ModemInfo(Rec&).VendorName)
  397.         BrandNo = SearchModemList(ModemBrand$)
  398.         If ModemBrand$ <> LastBrand$ And BrandNo = 0 Then
  399.         LastBrand$ = ModemBrand$
  400.         List1.AddItem ModemBrand$
  401.         List1.ItemData(List1.NewIndex) = Rec&
  402.         BrandNo = List1.NewIndex
  403.         End If
  404.         If CurModemNumber& = MW_ModemInfo(Rec&).ModemNumber Then
  405.         Temp$ = Trim$(MW_ModemInfo(Rec&).VendorName)
  406.         End If
  407.         Rec& = Rec& + 1
  408.     End If
  409.     Next
  410.     For I = Rec& To MW_NumRecords&
  411.     MW_ModemInfo(I).DeletedFlag = True
  412.     Next
  413.     Close DataFileNum
  414.     NumBrands = List1.ListCount
  415.     ReDim MW_LinkRecords(1 To NumBrands)
  416.     For Rec& = 1 To NumBrands
  417.     MW_LinkRecords(Rec&).VendorName = List1.List(Rec& - 1)
  418.     MW_LinkRecords(Rec&).Record = List1.ItemData(Rec& - 1)
  419.     If Temp$ = Trim$(MW_LinkRecords(Rec&).VendorName) Then
  420.         List1Index = Rec& - 1
  421.     End If
  422.     Next
  423.     '-- Set current List2 index (model)
  424.     If CurModemNumber& Then
  425.     List1.ListIndex = List1Index
  426.     Else
  427.     List1.ListIndex = 0
  428.     List2.ListIndex = 0
  429.     End If
  430.     List1.TopIndex = List1.ListIndex
  431.     List2.TopIndex = List2.ListIndex
  432. End Sub
  433. Sub MUtil_Click (Index As Integer)
  434. Dim Tr As Integer, BackupFileNum As Integer, TotalDeleted As Integer, Found As Integer
  435. Dim T$, Temp$, BackupFile$, Rec&, MRec&, I&
  436.     Select Case Index
  437.     Case 1  '-- Edit Settings
  438.         '-- Find the Modem Number of the selected modem
  439.         T$ = List2.List(List2.ListIndex)
  440.         For Rec& = 1 To MW_NumRecords&
  441.         If MW_ModemInfo(Rec&).ModemName = T$ Then
  442.             Exit For
  443.         End If
  444.         Next
  445.         If Rec& = MW_NumRecords& + 1 Then
  446.         Beep
  447.         MsgBox "Invalid Modem in database"
  448.         Exit Sub
  449.         End If
  450.         MWModStr.ModemNumber.Caption = " " & Trim$(Str$(MW_ModemInfo(Rec&).ModemNumber))
  451.         MWModStr.HighestBaud.Text = " " & Trim$(Str$(MW_ModemInfo(Rec&).HighestBaud))
  452.         Temp$ = MW_ModemInfo(Rec&).VendorName
  453.         MWModStr.Vendor.Text = " " & Trim$(Temp$)
  454.         Temp$ = MW_ModemInfo(Rec&).ModemName
  455.         MWModStr.Model.Text = " " & Trim$(Temp$)
  456.         Temp$ = MW_ModemInfo(Rec&).InitString
  457.         MWModStr.Init.Text = ZTrim$(Temp$)
  458.         Temp$ = MW_ModemInfo(Rec&).Connect
  459.         MWModStr.Connect.Text = ZTrim$(Temp$)
  460.         Temp$ = MW_ModemInfo(Rec&).Answer
  461.         MWModStr.Answer.Text = ZTrim$(Temp$)
  462.         Temp$ = MW_ModemInfo(Rec&).Busy
  463.         MWModStr.Busy.Text = ZTrim$(Temp$)
  464.         Temp$ = MW_ModemInfo(Rec&).Dial
  465.         MWModStr.Dial.Text = ZTrim$(Temp$)
  466.         Temp$ = MW_ModemInfo(Rec&).Attention
  467.         MWModStr.Attention.Text = ZTrim$(Temp$)
  468.         Temp$ = MW_ModemInfo(Rec&).Hangup
  469.         MWModStr.Hangup.Text = ZTrim$(Temp$)
  470.         Temp$ = MW_ModemInfo(Rec&).Reset
  471.         MWModStr.ResetStr.Text = ZTrim$(Temp$)
  472.         CurRec& = Rec&
  473.         MWModStr.Show 1
  474.     Case 2  '-- Add Modem
  475.      
  476.         '-- Find the Modem Number of the selected modem
  477.         MRec& = MW_NumRecords& + 1
  478.         Rec& = MRec&
  479.         ReDim Preserve MW_ModemInfo(1 To Rec&) As MW_ModemInfoType
  480.         Do
  481.         MRec& = MRec& - 1
  482.         MW_ModemInfo(Rec&).ModemNumber = MW_ModemInfo(MRec&).ModemNumber + 1
  483.         Loop While MW_ModemInfo(MRec&).DeletedFlag
  484.         MW_ModemInfo(Rec&).HighestBaud = 57600
  485.         MW_ModemInfo(Rec&).VendorName = ""
  486.         MW_ModemInfo(Rec&).ModemName = ""
  487.         MW_ModemInfo(Rec&).InitString = "AT^M"
  488.         MWModStr.ModemNumber.Caption = " " & Trim$(Str$(MW_ModemInfo(Rec&).ModemNumber))
  489.         MWModStr.HighestBaud.Text = " " & Trim$(Str$(MW_ModemInfo(Rec&).HighestBaud))
  490.         Temp$ = MW_ModemInfo(Rec&).ModemName
  491.         MWModStr.Model.Text = " " & Trim$(Temp$)
  492.         Temp$ = MW_ModemInfo(Rec&).InitString
  493.         MWModStr.Init.Text = ZTrim$(Temp$)
  494.         CurRec& = -Rec&
  495.         MWModStr.Show 1
  496.         If MWModStr.Tag = " " Then
  497.         '-- Add 1 to NumRecords
  498.         MW_NumRecords& = MW_NumRecords& + 1
  499.         '-- Reload the modem database
  500.         LoadModemData
  501.         End If
  502.     Case 3  '-- Delete Modem
  503.         '-- Find the Modem Number of the selected modem
  504.         T$ = List2.List(List2.ListIndex)
  505.         For Rec& = 1 To MW_NumRecords&
  506.         If MW_ModemInfo(Rec&).ModemName = T$ Then
  507.             Exit For
  508.         End If
  509.         Next
  510.         If Rec& = MW_NumRecords& + 1 Then Stop
  511.         
  512.         '-- Delete the item from the array.
  513.         MW_ModemInfo(Rec&).DeletedFlag = True
  514.         
  515.         '-- Mark the record in the file for deletion.
  516.         DataFile$ = App.Path & "\MODEMS.DAT"
  517.         On Error Resume Next
  518.         DataFileNum = FreeFile
  519.         Open DataFile$ For Binary As DataFileNum
  520.         Tr = True
  521.         Put #DataFileNum, 5 + (Rec& * LenModemType) - LenModemType, Tr
  522.         Close DataFileNum
  523.         
  524.         '-- Delete items from the listboxes
  525.         List2.RemoveItem List2.ListIndex
  526.         If List2.ListCount = 0 Then
  527.         List1.RemoveItem List1.ListIndex
  528.         End If
  529.         
  530.         List1_Click
  531.     Case 5  '-- Pack Database
  532.         MousePointer = 11
  533.         '-- Make a copy of the database
  534.         BackupFile$ = App.Path & "\MODEMS.BAK"
  535.         FileCopy DataFile$, BackupFile$
  536.         Kill DataFile$
  537.         '-- Open the backup file
  538.         BackupFileNum = FreeFile
  539.         Open BackupFile$ For Binary As BackupFileNum
  540.         '-- Read the total number of records
  541.         Get #BackupFileNum, 1, MW_NumRecords&
  542.         '-- Create an array to store them
  543.         ReDim Record(1 To MW_NumRecords&) As MW_ModemInfoType
  544.         '-- Read all non-deleted records into Record()
  545.         MRec& = 1
  546.         For Rec& = 1 To MW_NumRecords&
  547.         Get #BackupFileNum, , Record(MRec&)
  548.         If Record(Rec&).DeletedFlag Then
  549.             TotalDeleted = TotalDeleted + 1
  550.         Else
  551.             MRec& = MRec& + 1
  552.         End If
  553.         Next
  554.         '-- Subtract the total deleted from the number of records
  555.         MW_NumRecords& = MW_NumRecords& - TotalDeleted
  556.         
  557.         '-- Write the new total to MODEMS.DAT
  558.         DataFileNum = FreeFile
  559.         Open DataFile$ For Binary As DataFileNum
  560.         Put #DataFileNum, 1, MW_NumRecords&
  561.         '-- Change the LinkRecords
  562.         For Rec& = 1 To MW_NumRecords&
  563.         If Record(Rec&).LinkRecord Then
  564.             Found = False
  565.             For I& = Rec& + 1 To MW_NumRecords&
  566.             If Record(I&).VendorName = Record(Rec&).VendorName Then
  567.                 Record(Rec&).LinkRecord = I&
  568.                 Found = True
  569.                 Exit For
  570.             End If
  571.             Next
  572.             If Not Found Then
  573.             Record(Rec&).LinkRecord = 0&
  574.             End If
  575.         End If
  576.         Put #DataFileNum, , Record(Rec&)
  577.         Next
  578.         Close #DataFileNum, #BackupFileNum
  579.         Erase Record
  580.         LoadModemData
  581.         MousePointer = 0
  582.     End Select
  583. End Sub
  584. Function SearchModemList (Criteria$)
  585. Dim I As Integer, L As Integer, LoPoint%, HiPoint%, CurRecord&, LastPoint%
  586. Dim Found%, ModemBrand$, ModemSearch$
  587. If Criteria$ = List1.List(List1.NewIndex) Then
  588.     SearchModemList = List1.NewIndex + 1
  589.     Exit Function
  590. End If
  591. If List1.ListCount > 1 Then
  592.     Found% = 0
  593.     ModemSearch$ = UCase$(Criteria$)
  594.     CurRecord& = List1.ListCount
  595.     L = CurRecord& \ 2
  596.     LoPoint = 0: HiPoint = CurRecord& - 1
  597.     Do
  598.     LastPoint = L
  599.     ModemBrand$ = UCase$(Trim$(List1.List(L)))
  600.     Select Case ModemBrand$
  601.         Case Is > ModemSearch$
  602.         HiPoint = L
  603.         L = LoPoint + ((L - LoPoint) \ 2)
  604.         If L = LastPoint And LastPoint > LoPoint Then L = L - 1
  605.         Case Is < ModemSearch$
  606.         LoPoint = L
  607.         L = L + ((HiPoint - L) \ 2)
  608.         If L = LastPoint And LastPoint < HiPoint Then L = L + 1
  609.         Case Else
  610.         Found% = L + 1
  611.         Exit Do
  612.     End Select
  613.     Loop Until L = LoPoint Or L = HiPoint
  614. End If
  615. SearchModemList = Found%
  616. End Function
  617.