Public Function jieshou() '接收数据处理为16进制Dim i As IntegerFor i = 0 To UBound(bytInput)If Len(Hex(bytInput(i))) = 1 ThenstrData = strData & "0" & Hex(bytInput(i))ElsestrData = strData & Hex(bytInput(i))End IfNextText1.Text = strDataEnd FunctionPrivate Sub mscomm1_OnComm()Dim intInputLen As Integer Select Case MSComm1.CommEvent
 
 Case comEvReceiveMSComm1.InputMode = comInputModeBinary '二进制接收intInputLen = MSComm1.InBufferCountReDim bytInput(intInputLen)bytInput = MSComm1.Inputjieshou
......用断点调试 发现Text1.Text = strData="f000D000"
可我要收回来的是"f000D00000C0"但是我在界面上放的text控件里显示的 却是对的"f000D00000C0"还有这里总提示 下标越界这是怎么回事  谢谢请帮忙

解决方案 »

  1.   

     补充 是Hex(bytInput(i)) 总提示 下标越界
      

  2.   

    代码完整性有问题:
    Option Explicit
        Dim bytInput() As Byte
        Dim strData As String
    Public Function jieshou() '接收数据处理为16进制
        Dim i As Integer
        For i = 0 To UBound(bytInput)
            If Len(Hex(bytInput(i))) = 1 Then
                strData = strData & "0" & Hex(bytInput(i))
            Else
                strData = strData & Hex(bytInput(i))
            End If
        Next
        Text1.Text = strData
    End Function
    Private Sub Form_Load()
        MSComm1.Settings = "9600,N,8,1"
        MSComm1.RThreshold = 1
        MSComm1.PortOpen = True
    End SubPrivate Sub mscomm1_OnComm()
        Dim buffer As String
        Dim intInputLen As Integer
        Select Case MSComm1.CommEvent
            Case comEvReceive
            MSComm1.InputMode = comInputModeBinary '二进制接收
            intInputLen = MSComm1.InBufferCount
            ReDim bytInput(intInputLen)
                bytInput = MSComm1.Input
                jieshou
        End Select
    End Sub