求助Mscomm接收数据后Mid截取字符问题
Option ExplicitDim indata As String
Private Sub Command1_Click()
Dim aa(46) As Byte
aa(0) = &H55
aa(1) = &H55
aa(2) = &HF0
aa(3) = &H29
aa(4) = &HE7
aa(5) = &H4C
aa(6) = &H61
aa(7) = &H63
aa(8) = &H6B
aa(9) = &H20
aa(10) = &H6F
aa(11) = &H66
aa(12) = &H20
aa(13) = &H5A
aa(14) = &H65
aa(15) = &H72
aa(16) = &H6F
aa(17) = &HA
aa(18) = &H52
aa(19) = &H65
aa(20) = &H70
aa(21) = &H6F
aa(22) = &H72
aa(23) = &H74
aa(24) = &H20
aa(25) = &H54
aa(26) = &H69
aa(27) = &H6D
aa(28) = &H65
aa(29) = &H3A
aa(30) = &HA
aa(31) = &H30
aa(32) = &H34
aa(33) = &H2F
aa(34) = &H31
aa(35) = &H32
aa(36) = &H20
aa(37) = &H20
aa(38) = &H31
aa(39) = &H34
aa(40) = &H3A
aa(41) = &H30
aa(42) = &H32
aa(43) = &HF0
aa(44) = &HD
aa(45) = &H55
aa(46) = &H55
Text1.Text = ""
Text2.Text = ""
indata = ""
MSComm1.InBufferCount = 0
MSComm1.OutBufferCount = 0
MSComm1.Output = aa '发送数据
End Sub
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 = ""
indata = ""
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
Text1.Text = Trim(indata)
Text4.Text = Mid(Trim(indata), 18, Len(indata) - 27) '问题代码行
End Select
End Sub
想请教下Mid(Trim(indata), 18, Len(indata) - 27)这段代码为何报错(报错内容为:实时错误‘5’,无效的过程调用或参数),我是做单机发送及接收数据的,根据显示变量indata当作的长度为140,也就是a()数组当中的数据,为什么把Len(indata) - 27这段改成"数值"就可以,而用表达式就不行
[此贴子已经被作者于2016-12-29 14:36编辑过]