Private Sub Mscomm1_OnComm()
    Dim inByte() As Byte
    Dim tmp As Vatiant
    Dim i As Integer
    Dim l As Long, q As Long, e As Long, t As Long, u As Long, k As Long, s As Long, b As Long, c As Long
    Select Case MSComm1.CommEvent
           Case comEvReceive
                tmp = MSComm1.Input
                
                inByte = tmp
           For i = 0 To UBound(inByte)
                strData = strData & Right("0" & Hex(inByte(i)), 2)
           Next
代码是这样的,接收缓存区的数据都在tmp里边了,但是我怎么知道他们跑里边一共都多少个字节阿,怎么判断,如果我想把tmp里边的数据按字节分别判断,怎么实现阿?

解决方案 »

  1.   

    字符串就mid(tmp,i,1)
    数组就XXX(i)
    注意下标从0开始
    想做编程,这些最基础的语法、函数要了解一点呀。
      

  2.   

    for i = 0 to ubound(inbyte) step 2
    debug.print chr(inbyte(i))
    next
      

  3.   

    我刚学,说的不清,如果我收到
    01 10810010811081001081090522110555021234EEEE051106090500005110816206001083450200822000000000003050 
    03
    上边这么一组数,01是头,03 是尾。我想把中间的数据反转译,我怎么做循环。
    这是我写的一段循环代码,现在有问题,请帮忙找出,谢谢!
               If Hex(inByte(0)) = 1 Then
               str = str & "0" & Hex(inByte(0))
               e = 1
               While ((Hex(inByte(e))) <> 3)
               If Hex(inByte(e)) = 10 Then
                  If Hex(inByte(e + 1)) = 81 Then
                  str = str & "0" & 1
                  e = e + 1
                  ElseIf Hex(inByte(e + 1)) = 83 Then
                  str = str & "0" & 3
                  e = e + 1
                  ElseIf Hex(inByte(e + 1)) = 90 Then
                  str = str & "0" & 10
                  e = e + 1
                  Else
                  End If
               Else
                  str = str & "0" & Hex(inByte(e))
                  e = e + 1
                  End If
                 end while