home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Tool Box
/
SIMS_2.iso
/
update
/
crescent
/
mwupd
/
mwmodem.frm
next >
Wrap
Text File
|
1994-10-17
|
21KB
|
738 lines
VERSION 2.00
Begin Form MWModem
BorderStyle = 3 'Fixed Double
Caption = "Modem Database"
ClientHeight = 2616
ClientLeft = 648
ClientTop = 2268
ClientWidth = 6720
Height = 3264
Icon = MWMODEM.FRX:0000
Left = 600
LinkTopic = "Form2"
MaxButton = 0 'False
ScaleHeight = 2616
ScaleWidth = 6720
Top = 1668
Width = 6816
Begin TextBox TbPort
Height = 285
Left = 1680
TabIndex = 7
Text = "2"
Top = 2040
Width = 495
End
Begin CommandButton BtnOkExit
Cancel = -1 'True
Caption = "Cancel"
Height = 372
Index = 1
Left = 5520
TabIndex = 5
Top = 2040
Width = 972
End
Begin CommandButton BtnOkExit
Caption = "OK"
Default = -1 'True
Height = 375
Index = 0
Left = 4680
TabIndex = 4
Top = 2040
Width = 735
End
Begin ListBox List2
Height = 1560
Left = 2160
TabIndex = 1
Top = 360
Width = 4332
End
Begin ListBox List1
Height = 1560
Left = 240
Sorted = -1 'True
TabIndex = 0
Top = 360
Width = 1812
End
Begin Label Label1
Alignment = 1 'Right Justify
Caption = "Comm Port:"
Height = 255
Index = 2
Left = 240
TabIndex = 6
Top = 2050
Width = 1335
End
Begin Label Label1
Caption = "Model:"
Height = 252
Index = 1
Left = 2160
TabIndex = 3
Top = 120
Width = 852
End
Begin Label Label1
Caption = "Make:"
Height = 252
Index = 0
Left = 240
TabIndex = 2
Top = 120
Width = 852
End
Begin Menu MenuUtil
Caption = "&Utilities"
Begin Menu MUtil
Caption = "&Edit Settings"
Index = 1
End
Begin Menu MUtil
Caption = "&Add Modem"
Index = 2
End
Begin Menu MUtil
Caption = "&Delete Modem"
Index = 3
End
Begin Menu MUtil
Caption = "-"
Index = 4
End
Begin Menu MUtil
Caption = "&Pack Database"
Index = 5
End
End
End
Option Explicit
'-- ModemWare Copyright (c) 1992 - 1994 Crescent Software.
' Written by Carl Franklin with help from and thanks to Bill Conley.
'001 10/17/94 - Fixed bug that caused Modem Number to be set to 1 when
' adding a new modem to a databse that had deleted modems.
Dim DataFileNum As Integer
Dim CurModemNumber&
Sub BtnOkExit_Click (Index As Integer)
Dim PortNum As Integer, Timeout As Integer, ErrFlag As Integer, C As Integer
Dim Result As Integer, ModemIndex As Integer, Dummy As Integer
Dim OldCap$, T$, SetStr$, InitString$, Temp$, NextCmd$, ConfigFile$, AppName$
Dim OldSettings$, Rec&, HighestBaud&
OldCap$ = Caption
If Index Then
MW_CancelFlag = True
Tag = ""
GoTo MWModemExit:
Else
InitModemWare
'-- Find the Modem Number of the selected modem
T$ = List2.List(List2.ListIndex)
For Rec& = 1 To MW_NumRecords&
If MW_ModemInfo(Rec&).ModemName$ = T$ Then
Exit For
End If
Next
'-- Try to configure the modem.
On Error Resume Next
If Trim$(T$) = "Null Modem" Then GoTo MWSaveModemData
'-- Get InitString
InitString$ = ZTrim$(MW_ModemInfo(Rec&).InitString)
'-- Get the port number
PortNum = Val(TbPort.Text)
If PortNum = 0 Then
MsgBox "No Port Specified"
Exit Sub
End If
'-- Get the Settings
HighestBaud& = MW_ModemInfo(Rec&).HighestBaud
OldSettings$ = MW_Global_Comm1.Settings
If HighestBaud& >= 2400 Then
SetStr$ = "2400,N,8,1"
Else
SetStr$ = "300,N,8,1"
End If
MW_Global_Comm1.CommPort = PortNum
MW_Global_Comm1.Settings = SetStr$
On Error Resume Next
MW_Global_Comm1.PortOpen = True
If Err Then
MsgBox "COM" & LTrim$(Str$(PortNum)) & " is not available"
Exit Sub
End If
'-- Set an initial Timeout value
Timeout = 30
Caption = "Configuring your modem, please wait..."
ErrFlag = False
Screen.MousePointer = 11
Temp$ = RemoveCaret$(ZTrim$(InitString$))
Do
C = InStr(Temp$, MW_CR$)
If C Then
NextCmd$ = ZTrim$(Left$(Temp$, C))
If Len(Temp$) > C Then
Temp$ = Mid$(Temp$, C + 1)
End If
Else
Exit Do
End If
MWTryAgain:
Call SendModemCmd(MW_Global_Comm1, NextCmd$, 1, Timeout, Result)
Select Case Result
Case MW_RESULT_OK
'-- Exit the loop
Exit Do
Case MW_RESULT_ERROR, MW_RESULT_TIMEOUT
If ErrFlag = False Then
Caption = "An Error occurred, trying again.."
Timeout = Timeout + 10
ErrFlag = True
GoTo MWTryAgain:
Else
Caption = OldCap$
Screen.MousePointer = 0
MsgBox "Error: You may have picked the wrong modem."
If MW_Global_Comm1.PortOpen Then MW_Global_Comm1.PortOpen = False
Exit Sub
End If
Case Else
Caption = OldCap$
Screen.MousePointer = 0
MsgBox MWErrorMsg$()
If MW_Global_Comm1.PortOpen Then MW_Global_Comm1.PortOpen = False
Exit Sub
End Select
'-- Pause before trying again
MWPause 3
Loop
MWSaveModemData:
'-- Save info in config file.
Caption = "Saving Information..."
'-- Get the configuration INI filename
ConfigFile$ = GetConfigFileName$()
AppName$ = "Modem_" & MW_Global_Comm1.Tag
'-- Get the Modem's Index in the MWCurModem array
ModemIndex = GetModemIndex(MW_Global_Comm1)
If ModemIndex = 0 Then
Stop
End If
'-- Save Modem Number
Temp$ = LTrim$(Str$(MW_ModemInfo(Rec&).ModemNumber))
Dummy = MWPutConfigString(AppName$, "ModemNumber", Temp$, ConfigFile$)
MW_CurModem(ModemIndex).ModemNumber = MW_ModemInfo(Rec&).ModemNumber
'-- Save Modem Name
Temp$ = ZTrim$(MW_ModemInfo(Rec&).ModemName)
If Len(Temp$) = 0 Then Temp$ = "Generic 2400 Baud Modem"
Dummy = MWPutConfigString(AppName$, "ModemName", Temp$, ConfigFile$)
MW_CurModem(ModemIndex).ModemName = MW_ModemInfo(Rec&).ModemName
'-- Save Highest Baud rate
Temp$ = LTrim$(Str$(MW_ModemInfo(Rec&).HighestBaud))
If Len(Temp$) = 0 Then Temp$ = "2400"
Dummy = MWPutConfigString(AppName$, "HighestBaud", Temp$, ConfigFile$)
MW_CurModem(ModemIndex).HighestBaud = MW_ModemInfo(Rec&).HighestBaud
'-- Save Init String
Temp$ = ZTrim$(MW_ModemInfo(Rec&).InitString)
If Len(Temp$) = 0 Then Temp$ = "AT^M"
Dummy = MWPutConfigString(AppName$, "InitString", Temp$, ConfigFile$)
MW_CurModem(ModemIndex).InitString = MW_ModemInfo(Rec&).InitString
'-- Save Connect String
Temp$ = ZTrim$(MW_ModemInfo(Rec&).Connect)
If Len(Temp$) = 0 Then Temp$ = "CONNECT"
Dummy = MWPutConfigString(AppName$, "Connect", Temp$, ConfigFile$)
MW_CurModem(ModemIndex).Connect = MW_ModemInfo(Rec&).Connect
'-- Save Attention String
Temp$ = ZTrim$(MW_ModemInfo(Rec&).Attention)
If Len(Temp$) = 0 Then Temp$ = "AT"
Dummy = MWPutConfigString(AppName$, "Attention", Temp$, ConfigFile$)
MW_CurModem(ModemIndex).Attention = MW_ModemInfo(Rec&).Attention
'-- Save Hangup String
Temp$ = ZTrim$(MW_ModemInfo(Rec&).Hangup)
If Len(Temp$) = 0 Then Temp$ = "ATH^M"
Dummy = MWPutConfigString(AppName$, "Hangup", Temp$, ConfigFile$)
MW_CurModem(ModemIndex).Hangup = MW_ModemInfo(Rec&).Hangup
'-- Save Reset String
Temp$ = ZTrim$(MW_ModemInfo(Rec&).Reset)
If Len(Temp$) = 0 Then Temp$ = "ATZ^M"
Dummy = MWPutConfigString(AppName$, "Reset", Temp$, ConfigFile$)
MW_CurModem(ModemIndex).Reset = MW_ModemInfo(Rec&).Reset
'-- Save Answer String
Temp$ = ZTrim$(MW_ModemInfo(Rec&).Answer)
If Len(Temp$) = 0 Then Temp$ = "ATA^M"
Dummy = MWPutConfigString(AppName$, "Answer", Temp$, ConfigFile$)
MW_CurModem(ModemIndex).Answer = MW_ModemInfo(Rec&).Answer
'-- Save Dial String
Temp$ = ZTrim$(MW_ModemInfo(Rec&).Dial)
If Len(Temp$) = 0 Then Temp$ = "ATDT"
Dummy = MWPutConfigString(AppName$, "Dial", Temp$, ConfigFile$)
MW_CurModem(ModemIndex).Dial = MW_ModemInfo(Rec&).Dial
'-- Save Busy String
Temp$ = ZTrim$(MW_ModemInfo(Rec&).Busy)
If Len(Temp$) = 0 Then Temp$ = "BUSY"
Dummy = MWPutConfigString(AppName$, "Busy", Temp$, ConfigFile$)
MW_CurModem(ModemIndex).Busy = MW_ModemInfo(Rec&).Busy
'-- Set the Tag to the port/modem spcecified
T$ = "COM" & LTrim$(Str$(PortNum)) & ": " & MW_ModemInfo(Rec&).ModemName
Tag = T$
End If
MWModemExit:
If MW_Global_Comm1.PortOpen Then
MW_Global_Comm1.PortOpen = False
End If
Caption = OldCap$
Screen.MousePointer = 0
Close DataFileNum
Hide
End Sub
Sub Form_Activate ()
TbPort.Text = Str$(MW_Global_Comm1.CommPort)
BtnOkExit(0).SetFocus
List1.SetFocus
End Sub
Sub Form_Load ()
CenterForm Me
Screen.MousePointer = 11
LoadModemData
Screen.MousePointer = 0
End Sub
Sub List1_Click ()
Dim L As Integer, LoPoint As Integer, HiPoint As Integer, LastPoint As Integer
Dim List2Index As Integer
Dim Criteria$, ModemBrand$, Counter&, Match&, CurRecord&, NewRec&
Criteria$ = UCase$(List1.List(List1.ListIndex))
'-- Find the first
CurRecord& = UBound(MW_LinkRecords)
L = CurRecord& \ 2
LoPoint = 1: HiPoint = CurRecord&
Do
LastPoint = L
ModemBrand$ = UCase$(Trim$(MW_LinkRecords(L).VendorName))
Select Case ModemBrand$
Case Is > Criteria$
HiPoint = L
L = LoPoint + ((L - LoPoint) \ 2)
If L = LastPoint And LastPoint > LoPoint Then L = L - 1
Case Is < Criteria$
LoPoint = L
L = L + ((HiPoint - L) \ 2)
If L = LastPoint And LastPoint < HiPoint Then L = L + 1
Case Else
Exit Do
End Select
Loop Until L = LoPoint Or L = HiPoint
CurRecord& = MW_LinkRecords(L).Record
'-- Clear the list box
List2.Clear
'-- Save record info and put the first modem into List2
Do
ModemBrand$ = UCase$(Trim$(MW_ModemInfo(CurRecord&).VendorName))
If ModemBrand$ = Criteria$ Then
If MW_ModemInfo(CurRecord&).DeletedFlag = 0 Then
List2.AddItem MW_ModemInfo(CurRecord&).ModemName
If MW_ModemInfo(CurRecord&).ModemNumber = CurModemNumber& Then
List2Index = List2.NewIndex
End If
End If
If MW_ModemInfo(CurRecord&).LinkRecord Then
CurRecord& = MW_ModemInfo(CurRecord&).LinkRecord
Else
CurRecord& = CurRecord& + 1
If CurRecord& > MW_NumRecords& Then Exit Do
End If
Else
Exit Do
End If
Loop
List2.ListIndex = List2Index
End Sub
Sub List2_DblClick ()
BtnOkExit(0) = True
End Sub
Sub LoadModemData ()
Dim Dummy As Integer, I As Integer, Linked As Integer, BrandNo As Integer, List1Index As Integer
Dim ConfigFile$, AppName$, Temp$, ModemBrand$, LastBrand$
Dim SrchRec&, Rec&
If DataFileNum Then
Close DataFileNum
DataFileNum = 0
End If
List1.Clear
List2.Clear
'-- Get the configuration INI filename
ConfigFile$ = GetConfigFileName$()
'-- All Modem Settings are listed under "[Modem_<Tag property>]" in the INI file.
AppName$ = "Modem_" & MW_Global_Comm1.Tag
'-- Get Modem Number
Temp$ = Space$(10)
Dummy = MWGetConfigString(AppName$, "ModemNumber", "", Temp$, 10, ConfigFile$)
CurModemNumber& = Val(Temp$)
'-- Open MODEMS.DAT
DataFile$ = App.Path
If Right$(DataFile$, 1) = "\" Then
DataFile$ = DataFile$ & "MODEMS.DAT"
Else
DataFile$ = DataFile$ & "\MODEMS.DAT"
End If
On Error Resume Next
DataFileNum = FreeFile
Open DataFile$ For Binary As DataFileNum
If Err Then
MsgBox "Can not find MODEMS.DAT. Please copy it to where your .EXE file is."
Unload MWModem
Exit Sub
End If
'-- Read the total number of records
Get #DataFileNum, , MW_NumRecords&
'-- Grow the array and read the data
ReDim MW_ModemInfo(1 To MW_NumRecords&) As MW_ModemInfoType
LastBrand$ = ""
NumBrands = 0
Rec& = 1
For I = 1 To MW_NumRecords&
Get #DataFileNum, , MW_ModemInfo(Rec&)
If Not MW_ModemInfo(Rec&).DeletedFlag Then
ModemBrand$ = Trim$(MW_ModemInfo(Rec&).VendorName)
BrandNo = SearchModemList(ModemBrand$)
If ModemBrand$ <> LastBrand$ And BrandNo = 0 Then
LastBrand$ = ModemBrand$
List1.AddItem ModemBrand$
List1.ItemData(List1.NewIndex) = Rec&
BrandNo = List1.NewIndex
End If
If CurModemNumber& = MW_ModemInfo(Rec&).ModemNumber Then
Temp$ = Trim$(MW_ModemInfo(Rec&).VendorName)
End If
Rec& = Rec& + 1
End If
Next
For I = Rec& To MW_NumRecords&
MW_ModemInfo(I).DeletedFlag = True
Next
Close DataFileNum
NumBrands = List1.ListCount
ReDim MW_LinkRecords(1 To NumBrands)
For Rec& = 1 To NumBrands
MW_LinkRecords(Rec&).VendorName = List1.List(Rec& - 1)
MW_LinkRecords(Rec&).Record = List1.ItemData(Rec& - 1)
If Temp$ = Trim$(MW_LinkRecords(Rec&).VendorName) Then
List1Index = Rec& - 1
End If
Next
'-- Set current List2 index (model)
If CurModemNumber& Then
List1.ListIndex = List1Index
Else
List1.ListIndex = 0
List2.ListIndex = 0
End If
List1.TopIndex = List1.ListIndex
List2.TopIndex = List2.ListIndex
End Sub
Sub MUtil_Click (Index As Integer)
Dim Tr As Integer, BackupFileNum As Integer, TotalDeleted As Integer, Found As Integer
Dim T$, Temp$, BackupFile$, Rec&, MRec&, I&
Select Case Index
Case 1 '-- Edit Settings
'-- Find the Modem Number of the selected modem
T$ = List2.List(List2.ListIndex)
For Rec& = 1 To MW_NumRecords&
If MW_ModemInfo(Rec&).ModemName = T$ Then
Exit For
End If
Next
If Rec& = MW_NumRecords& + 1 Then
Beep
MsgBox "Invalid Modem in database"
Exit Sub
End If
MWModStr.ModemNumber.Caption = " " & Trim$(Str$(MW_ModemInfo(Rec&).ModemNumber))
MWModStr.HighestBaud.Text = " " & Trim$(Str$(MW_ModemInfo(Rec&).HighestBaud))
Temp$ = MW_ModemInfo(Rec&).VendorName
MWModStr.Vendor.Text = " " & Trim$(Temp$)
Temp$ = MW_ModemInfo(Rec&).ModemName
MWModStr.Model.Text = " " & Trim$(Temp$)
Temp$ = MW_ModemInfo(Rec&).InitString
MWModStr.Init.Text = ZTrim$(Temp$)
Temp$ = MW_ModemInfo(Rec&).Connect
MWModStr.Connect.Text = ZTrim$(Temp$)
Temp$ = MW_ModemInfo(Rec&).Answer
MWModStr.Answer.Text = ZTrim$(Temp$)
Temp$ = MW_ModemInfo(Rec&).Busy
MWModStr.Busy.Text = ZTrim$(Temp$)
Temp$ = MW_ModemInfo(Rec&).Dial
MWModStr.Dial.Text = ZTrim$(Temp$)
Temp$ = MW_ModemInfo(Rec&).Attention
MWModStr.Attention.Text = ZTrim$(Temp$)
Temp$ = MW_ModemInfo(Rec&).Hangup
MWModStr.Hangup.Text = ZTrim$(Temp$)
Temp$ = MW_ModemInfo(Rec&).Reset
MWModStr.ResetStr.Text = ZTrim$(Temp$)
CurRec& = Rec&
MWModStr.Show 1
Case 2 '-- Add Modem
'-- Find the Modem Number of the selected modem
MRec& = MW_NumRecords& + 1
Rec& = MRec&
ReDim Preserve MW_ModemInfo(1 To Rec&) As MW_ModemInfoType
Do
MRec& = MRec& - 1
MW_ModemInfo(Rec&).ModemNumber = MW_ModemInfo(MRec&).ModemNumber + 1
Loop While MW_ModemInfo(MRec&).DeletedFlag
MW_ModemInfo(Rec&).HighestBaud = 57600
MW_ModemInfo(Rec&).VendorName = ""
MW_ModemInfo(Rec&).ModemName = ""
MW_ModemInfo(Rec&).InitString = "AT^M"
MWModStr.ModemNumber.Caption = " " & Trim$(Str$(MW_ModemInfo(Rec&).ModemNumber))
MWModStr.HighestBaud.Text = " " & Trim$(Str$(MW_ModemInfo(Rec&).HighestBaud))
Temp$ = MW_ModemInfo(Rec&).ModemName
MWModStr.Model.Text = " " & Trim$(Temp$)
Temp$ = MW_ModemInfo(Rec&).InitString
MWModStr.Init.Text = ZTrim$(Temp$)
CurRec& = -Rec&
MWModStr.Show 1
If MWModStr.Tag = " " Then
'-- Add 1 to NumRecords
MW_NumRecords& = MW_NumRecords& + 1
'-- Reload the modem database
LoadModemData
End If
Case 3 '-- Delete Modem
'-- Find the Modem Number of the selected modem
T$ = List2.List(List2.ListIndex)
For Rec& = 1 To MW_NumRecords&
If MW_ModemInfo(Rec&).ModemName = T$ Then
Exit For
End If
Next
If Rec& = MW_NumRecords& + 1 Then Stop
'-- Delete the item from the array.
MW_ModemInfo(Rec&).DeletedFlag = True
'-- Mark the record in the file for deletion.
DataFile$ = App.Path & "\MODEMS.DAT"
On Error Resume Next
DataFileNum = FreeFile
Open DataFile$ For Binary As DataFileNum
Tr = True
Put #DataFileNum, 5 + (Rec& * LenModemType) - LenModemType, Tr
Close DataFileNum
'-- Delete items from the listboxes
List2.RemoveItem List2.ListIndex
If List2.ListCount = 0 Then
List1.RemoveItem List1.ListIndex
End If
List1_Click
Case 5 '-- Pack Database
MousePointer = 11
'-- Make a copy of the database
BackupFile$ = App.Path & "\MODEMS.BAK"
FileCopy DataFile$, BackupFile$
Kill DataFile$
'-- Open the backup file
BackupFileNum = FreeFile
Open BackupFile$ For Binary As BackupFileNum
'-- Read the total number of records
Get #BackupFileNum, 1, MW_NumRecords&
'-- Create an array to store them
ReDim Record(1 To MW_NumRecords&) As MW_ModemInfoType
'-- Read all non-deleted records into Record()
MRec& = 1
For Rec& = 1 To MW_NumRecords&
Get #BackupFileNum, , Record(MRec&)
If Record(Rec&).DeletedFlag Then
TotalDeleted = TotalDeleted + 1
Else
MRec& = MRec& + 1
End If
Next
'-- Subtract the total deleted from the number of records
MW_NumRecords& = MW_NumRecords& - TotalDeleted
'-- Write the new total to MODEMS.DAT
DataFileNum = FreeFile
Open DataFile$ For Binary As DataFileNum
Put #DataFileNum, 1, MW_NumRecords&
'-- Change the LinkRecords
For Rec& = 1 To MW_NumRecords&
If Record(Rec&).LinkRecord Then
Found = False
For I& = Rec& + 1 To MW_NumRecords&
If Record(I&).VendorName = Record(Rec&).VendorName Then
Record(Rec&).LinkRecord = I&
Found = True
Exit For
End If
Next
If Not Found Then
Record(Rec&).LinkRecord = 0&
End If
End If
Put #DataFileNum, , Record(Rec&)
Next
Close #DataFileNum, #BackupFileNum
Erase Record
LoadModemData
MousePointer = 0
End Select
End Sub
Function SearchModemList (Criteria$)
Dim I As Integer, L As Integer, LoPoint%, HiPoint%, CurRecord&, LastPoint%
Dim Found%, ModemBrand$, ModemSearch$
If Criteria$ = List1.List(List1.NewIndex) Then
SearchModemList = List1.NewIndex + 1
Exit Function
End If
If List1.ListCount > 1 Then
Found% = 0
ModemSearch$ = UCase$(Criteria$)
CurRecord& = List1.ListCount
L = CurRecord& \ 2
LoPoint = 0: HiPoint = CurRecord& - 1
Do
LastPoint = L
ModemBrand$ = UCase$(Trim$(List1.List(L)))
Select Case ModemBrand$
Case Is > ModemSearch$
HiPoint = L
L = LoPoint + ((L - LoPoint) \ 2)
If L = LastPoint And LastPoint > LoPoint Then L = L - 1
Case Is < ModemSearch$
LoPoint = L
L = L + ((HiPoint - L) \ 2)
If L = LastPoint And LastPoint < HiPoint Then L = L + 1
Case Else
Found% = L + 1
Exit Do
End Select
Loop Until L = LoPoint Or L = HiPoint
End If
SearchModemList = Found%
End Function