关于Mscomm如何清空接收显示框
Option ExplicitDim inData As String '串口接收显示数据变量
'--------------加载串口设置---------------
Private Sub Form_Load()
= 3
MSComm1.Settings = "9600,N,8,1"
MSComm1.InBufferSize = 1024
MSComm1.OutBufferSize = 4096
MSComm1.InBufferCount = 0
MSComm1.OutBufferCount = 0
MSComm1.SThreshold = 1
MSComm1.RThreshold = 1
MSComm1.InputMode = 1
MSComm1.InputLen = 0
MSComm1.PortOpen = True
Text2.Text = ""
End Sub
'--------------发送------------------
Private Sub Command1_Click()
Dim aa(0 To 14) As Byte
aa(0) = &H55
aa(1) = &H55
aa(2) = &HFA
aa(3) = &H9
aa(4) = &HE5
aa(5) = &H5
aa(6) = &H4
aa(7) = &H12
aa(8) = &H12
aa(9) = &H48
aa(10) = &H0
aa(11) = &H63
aa(12) = &HD
aa(13) = &H55
aa(14) = &H55
Text2.Text = "" '发送前清空Text2.text
MSComm1.InBufferCount = 0 '发送前清空接收缓冲区
Text1.Text = Hex(aa(0)) & " " & Hex(aa(1)) & " " & Hex(aa(2)) & " " & Hex(aa(3)) & " " & Hex(aa(4)) & " " _
& Hex(aa(5)) & " " & Hex(aa(6)) & " " & Hex(aa(7)) & " " & Hex(aa(8)) & " " & Hex(aa(9)) & " " & Hex(aa(10)) & " " _
& Hex(aa(11)) & " " & Hex(aa(12)) & " " & Hex(aa(13)) & " " & Hex(aa(14))
MSComm1.Output = aa '发送
End Sub
'-------退出----------
Private Sub Command3_Click()
End
End Sub
'---------------接收数据------------------
Private Sub MSComm1_OnComm()
Dim InByte() As Byte '定义一个二进制指针放接收到的数据
Dim i As Integer
Select Case
Case comEvReceive
InByte = MSComm1.Input '数据转移到指针
For i = LBound(InByte) To UBound(InByte)
If Len(Hex(InByte(i))) = 1 Then
inData = inData & "0" & Hex(InByte(i)) & Chr(32)
Else
inData = inData + Hex(InByte(i)) + Chr(32)
End If
Next i
Text2.Text = inData '数据显示
End Select
End Sub
以上代码是无法在发送时清空text2.text当中的数据,请教下如何清空!谢谢!