我设置的com口怎么不起作用呢?
我用combobox控件做的com口选择,但无论选择那个com口都可以正常运行(串口线连接的是com1口),那位能帮我看一下!谢了
Private Sub Combo1_Change() '下拉菜单,选择COM口
Dim COM As String
If Combo1.Text = "COM1" Then
COM = 1
ElseIf Combo1.Text = "COM2" Then
COM = 2
'ElseIf Combo1.Text = "COM3" Then
'MSComm1.CommPort = "COM3"
'ElseIf Combo1.Text = "COM4" Then
'MSComm1.CommPort = "COM4"
'ElseIf Combo1.Text = "COM5" Then
'MSComm1.CommPort = "COM5"
'ElseIf Combo1.Text = "COM6" Then
'MSComm1.CommPort = "COM6"
'ElseIf Combo1.Text = "COM7" Then
'MSComm1.CommPort = "COM7"
'ElseIf Combo1.Text = "COM8" Then
'MSComm1.CommPort = "COM8"
'ElseIf Combo1.Text = "COM9" Then
'MSComm1.CommPort = "COM9"
Else
End If
If MSComm1.PortOpen = True Then
MSComm1.CommPort = COM
End If
End Sub
[解决办法]
请将你的代码中的:
If MSComm1.PortOpen = True Then
MSComm1.CommPort = COM
End If
修改为:
If MSComm1.PortOpen Then Msccomm1.PortOpen=False
msccomm1.commport=com
msccomm1.portopen=true
在PortOpen=True时,是不能设置Commport的
[解决办法]
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If
MSComm1.CommPort = COM
MSComm1.PortOpen = True