vb串口 出错

来源:百度知道 编辑:UC知道 时间:2024/05/26 02:45:27
Option Explicit
Dim sj(2) As String
Dim sum As Integer

Private Sub Command1_Click()
MSComm1.Output = "key;utility"
MSComm1.Output = "key:ref"
MSComm1.Output = "KEY;display"
Print MSComm1.OutBufferCount
End Sub

Private Sub Command2_Click()

Text2.Text = MSComm1.Input

End Sub

Private Sub Command3_Click()
If Combo_RS232.Text = "COM1" Then
MSComm1.CommPort = 1
Else
If Combo_RS232.Text = "COM2" Then
MSComm1.CommPort = 2
Else
MSComm1.CommPort = 3
End If
End If

If Combo_Baudrate.Text = "9600" Then
MSComm1.Settings = "9600,n,8,1"
Else
If Combo_Baudrate.Text = "300" Then
MSComm1.Settings = "300,n,8,1"
Else
If Combo_Baudrate.

1楼指明的正确,LZ的代码存在明显错误,现修改LZ的代码:
Option Explicit
Dim sj(2) As String
Dim sum As Integer

Private Sub Command1_Click()
If MSComm1.PortOpen = True Then
MSComm1.Output = "key;utility"
MSComm1.Output = "key:ref"
MSComm1.Output = "KEY;display"
Print MSComm1.OutBufferCount
End If
End Sub

Private Sub Command2_Click()
If MSComm1.PortOpen = True Then
Text2.Text = MSComm1.Input
End If
End Sub

Private Sub Command3_Click()
If Combo_RS232.Text = "COM1" Then
MSComm1.CommPort = 1
ElseIf Combo_RS232.Text = "COM2" Then
MSComm1.CommPort = 2
ElseIf Combo_RS232.Text = "COM3" Then
MSComm1.CommPort = 3
End If
If Combo_Baudrate.Text = "9600" Then
MSComm1.Settings = "9600,n,8,1