这个是个好东西,当时也是搜了很多资料才做出来的,第一个界面用来选择串口,它可以自动搜索当前可用的串口,这个很重要,没有警告,不会崩溃。
先看程序。
Dim comn(9) As Byte Private Function jiance() Me.Combo1.Clear m = 0 On Error Resume Next For i = 1 To 10 Me.MSComm1.CommPort = i Me.MSComm1.PortOpen = True If Err.Number = 0 Then Me.Combo1.AddItem "串口" & i comn(m) = i m = m + 1 End If Me.MSComm1.PortOpen = False Err.Clear Next i Me.Combo1.ListIndex = 0 Command1.Enabled = True If m = 0 Then Me.Combo1.Text = "未检测到串口" Command1.Enabled = False End If End Function Private Sub Command1_Click() Cls Print comn(Me.Combo1.ListIndex) comnum = comn(Me.Combo1.ListIndex) Form1.Hide Form2.Show End Sub Private Sub Command2_Click() If MsgBox("确定要退出系统吗?",vbOKCancel,"退出提醒") = vbOK Then End End Sub Private Sub Command3_Click() Call jiance End Sub Private Sub Form_Load() Command1.Enabled = False Call jiance End Sub
运行截图这样的:
已经用到了我的一些项目中了,值得收藏。