📄 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 Form1
BorderStyle = 3 'Fixed Dialog
Caption = "测试Modem"
ClientHeight = 3270
ClientLeft = 45
ClientTop = 330
ClientWidth = 5655
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3270
ScaleWidth = 5655
ShowInTaskbar = 0 'False
StartUpPosition = 1 '所有者中心
Begin VB.CommandButton Cmd_Save
Caption = "保存设置"
Height = 375
Left = 3840
TabIndex = 4
Top = 1920
Width = 1095
End
Begin VB.CommandButton Cmd_Tset
Caption = "测试Modem"
Height = 375
Left = 2280
TabIndex = 3
Top = 1920
Width = 1095
End
Begin VB.CommandButton Cmd_Search
Caption = "检测端口号"
Height = 375
Left = 720
TabIndex = 2
Top = 1920
Width = 1095
End
Begin VB.Frame Frame1
Caption = "端口号"
Height = 975
Left = 720
TabIndex = 1
Top = 795
Width = 4215
Begin VB.OptionButton Option_Com
Caption = "COM4"
Height = 255
Index = 3
Left = 3120
TabIndex = 9
Top = 480
Width = 735
End
Begin VB.OptionButton Option_Com
Caption = "COM3"
Height = 255
Index = 2
Left = 2160
TabIndex = 8
Top = 480
Width = 735
End
Begin VB.OptionButton Option_Com
Caption = "COM2"
Height = 255
Index = 1
Left = 1200
TabIndex = 7
Top = 480
Width = 735
End
Begin VB.OptionButton Option_Com
Caption = "COM1"
Height = 255
Index = 0
Left = 240
TabIndex = 6
Top = 480
Width = 735
End
End
Begin MSCommLib.MSComm MSComm
Left = 120
Top = 240
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
End
Begin MSComctlLib.ProgressBar ProgressBar
Height = 255
Left = 720
TabIndex = 5
Top = 2640
Width = 4215
_ExtentX = 7435
_ExtentY = 450
_Version = 393216
Appearance = 1
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "测试Modem"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 210
Left = 2160
TabIndex = 0
Top = 240
Width = 945
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public ComX As Integer
'系统自动检测端口号
'方法:打开/关闭端口,如果出错,表示不可用端口
Private Sub Cmd_Search_Click()
On Error GoTo ComErr '如果打开端口号出错,则跳转,注意:不能跳转到循环体内。
Dim i As Integer
ProgressBar.Value = 0 '设置进度条为0
For i = 0 To 3 '禁用所有的选项
Option_Com(i).Enabled = False
Next
For i = 1 To 4
ProgressBar.Value = 25 * i
If MSComm.PortOpen Then MSComm.PortOpen = False '先关闭端口
MSComm.CommPort = i '设置MSCOMM的端口号
If MSComm.PortOpen Then MSComm.PortOpen = False
If MSComm.PortOpen = False Then MSComm.PortOpen = True
If ComX = 0 Then ComX = i '选定第一个可用的端口号
ComNext:
Next
If ComX = 0 Then End '无可用端口号,则退出
For i = 0 To 3 '启用所有的选项
Option_Com(i).Enabled = True
Next
Option_Com(ComX - 1).Value = True
ProgressBar.Value = 0
Exit Sub
ComErr:
Resume ComNext '返回到循环体内
End Sub
Private Sub Form_Load()
Dim i As Integer
ComX = 0 '设置COMX的初值
ProgressBar.Value = 0
'初始化COM,使所有的COM均不选中状态
For i = 0 To 3
Option_Com(i).Value = False
Next
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -