📄 form1.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form Dial
AutoRedraw = -1 'True
BorderStyle = 3 'Fixed Dialog
Caption = "Modem检测程序"
ClientHeight = 3180
ClientLeft = 45
ClientTop = 330
ClientWidth = 5100
Icon = "Form1.frx":0000
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3180
ScaleWidth = 5100
ShowInTaskbar = 0 'False
StartUpPosition = 2 '屏幕中心
Begin MSComctlLib.ProgressBar Bar1
Height = 255
Left = 240
TabIndex = 14
Top = 2640
Width = 4335
_ExtentX = 7646
_ExtentY = 450
_Version = 393216
Appearance = 1
Max = 10000
End
Begin VB.Timer Timer1
Interval = 1000
Left = 4320
Top = 1680
End
Begin VB.Frame Frame1
Caption = "端口号"
Height = 1875
Left = 255
TabIndex = 11
Top = 300
Width = 1185
Begin VB.OptionButton OptionCom2
Caption = "COM1"
Height = 255
Index = 0
Left = 270
TabIndex = 0
Top = 390
Value = -1 'True
Width = 810
End
Begin VB.OptionButton OptionCom2
Caption = "COM2"
Height = 255
Index = 1
Left = 255
TabIndex = 4
Top = 720
Width = 840
End
Begin VB.OptionButton OptionCom2
Caption = "COM3"
Height = 255
Index = 2
Left = 255
TabIndex = 5
Top = 1080
Width = 825
End
Begin VB.OptionButton OptionCom2
Caption = "COM4"
Height = 255
Index = 3
Left = 255
TabIndex = 6
Top = 1440
Width = 765
End
End
Begin VB.Frame Frame2
Caption = "Modem 速率"
Height = 1890
Left = 1560
TabIndex = 8
Top = 285
Width = 1365
Begin VB.OptionButton OptionBaud
Caption = "1200"
Height = 255
Index = 0
Left = 240
TabIndex = 1
Top = 345
Width = 885
End
Begin VB.OptionButton OptionBaud
Caption = "2400"
Height = 255
Index = 1
Left = 240
TabIndex = 7
Top = 645
Width = 915
End
Begin VB.OptionButton OptionBaud
Caption = "9600"
Height = 255
Index = 2
Left = 240
TabIndex = 13
Top = 945
Width = 855
End
Begin VB.OptionButton OptionBaud
Caption = "14400"
Height = 255
Index = 3
Left = 240
TabIndex = 10
Top = 1245
Width = 945
End
Begin VB.OptionButton OptionBaud
Caption = "28800"
Height = 255
Index = 4
Left = 240
TabIndex = 9
Top = 1545
Value = -1 'True
Width = 885
End
End
Begin VB.CommandButton Command2
Caption = "关闭(&C)"
Height = 405
Left = 3270
TabIndex = 3
Top = 840
Width = 1275
End
Begin VB.CommandButton Command1
Caption = "测试(&T)"
Height = 420
Left = 3270
TabIndex = 2
Top = 375
Width = 1275
End
Begin MSCommLib.MSComm MSComm1
Left = 3600
Top = 1680
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
End
Begin VB.Label Bar1L
AutoSize = -1 'True
Caption = "真在检测,请稍等..."
ForeColor = &H00000080&
Height = 180
Left = 285
TabIndex = 12
Top = 2355
Visible = 0 'False
Width = 1620
End
End
Attribute VB_Name = "Dial"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim PortName As Integer, ModemSpeed As String, I As Integer
Dim TimeoutAs As Boolean
Dim lngProcess As Long
Private Sub Command1_Click()
If MSComm1.PortOpen = True Then
Command1.Caption = "测试(&T)"
MSComm1.PortOpen = False
Exit Sub
End If
Command1.Caption = "取消测试"
Me.Height = 3390
For I = 0 To 3
If OptionCom2(I).Value = True Then
PortName = I + 1
Exit For
End If
Next
For I = 0 To 4
If OptionBaud(I).Value Then
ModemSpeed = OptionBaud(I).Caption
Exit For
End If
Next
Bar1L.Visible = True
Bar1.Visible = True
Bar1.Value = 0
MSComm1.Settings = ModemSpeed + ",n,8,1"
MSComm1.CommPort = PortName
On Error GoTo Invalible
MSComm1.PortOpen = True
MSComm1.InputLen = 0
MSComm1.Output = "AT" + Chr$(13)
Me.MousePointer = 11
Timer1.Enabled = True
Do
If TimeoutAs = True Then
Exit Do
End If
DoEvents
If MSComm1.PortOpen = False Then Exit Do
Loop Until InStr(MSComm1.Input, "OK")
If TimeoutAs = True Then
Timer1.Enabled = False
MsgBox "请检查调制解调器连接是否正常,打开了没有!", vbOKOnly + 32, "连接错误"
ElseIf MSComm1.PortOpen = True Then
Timer1.Enabled = False
Bar1.Value = 10000
MsgBox "检测正常通过,现在你可以使用Modem了!", vbOKOnly + 32, "一切正常"
SaveSetting App.EXEName, "Config", "BaudRate", ModemSpeed
SaveSetting App.EXEName, "Config", "PortName", PortName
End If
TimeoutAs = False
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If
Me.MousePointer = 0
Timer1.Enabled = False
Me.Height = 2805
Command1.Caption = "测试(&T)"
Bar1L.Visible = False
Bar1.Visible = False
Exit Sub
Invalible:
Dim ErrX As Integer
ErrX = Err.Number
Select Case ErrX
Case 8005
Bar1.Value = 10000
MsgBox "其它程序正在使用MODEM!", vbOKOnly + 32, "检测错误"
Me.Height = 2805
Bar1L.Visible = False
Bar1.Visible = False
Exit Sub
Case 8002
Bar1.Value = 10000
MsgBox "端口配置错误,重新设置!", vbOKOnly + 32, "检测错误"
Me.Height = 2805
Bar1L.Visible = False
Bar1.Visible = False
Exit Sub
End Select
MsgBox "检测没有通过,未知错误!", vbOKOnly + 32, "检测错误"
Bar1.Value = 10000
Me.MousePointer = 0
Me.Height = 2805
Command1.Caption = "测试(&T)"
Bar1L.Visible = False
Bar1.Visible = False
End Sub
Private Sub Command2_Click()
If Command1.Caption = "取消测试" Then
Call Command1_Click
End If
Unload Me
End
End Sub
Private Sub Form_Load()
Me.Height = 2805
Dim Rl As String
Rl = GetSetting(App.EXEName, "Config", "BaudRate")
Select Case Rl
Case "1200"
OptionBaud(0).Value = True
Case "2400"
OptionBaud(1).Value = True
Case "9600"
OptionBaud(2).Value = True
Case "14400"
OptionBaud(3).Value = True
Case "28800"
OptionBaud(4).Value = True
Case Else
OptionBaud(2).Value = True
End Select
Rl = GetSetting(App.EXEName, "Config", "PortName")
Select Case Rl
Case "1"
OptionCom2(0).Value = True
Case "2"
OptionCom2(1).Value = True
Case "3"
OptionCom2(2).Value = True
Case "4"
OptionCom2(3).Value = True
Case Else
OptionCom2(1).Value = True
End Select
Timer1.Enabled = False
TimeoutAs = False
End Sub
Private Sub Timer1_Timer()
lngProcess = lngProcess + 1
If lngProcess > 20 Then
TimeoutAs = True
lngProcess = 0
Bar1.Value = 0
Exit Sub
End If
Bar1.Value = Bar1 + 500
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -