Private Sub MSComm1_OnComm()
    If Command2.Caption = "停止接受" Then
        Select Case CommEvent
            Case comEvReceive
                temp = MSComm1.Input
                ReDim Preserve temp(UBound(temp)) As Byte
                For i = LBound(temp) To UBound(temp)
                    Text2 = Text2 & str$(temp(i)) & " "
                Next i
        End Select
    
    End If
    
End Subusb/ppi电缆的发送信号和接受信号都亮起,但是没有显示到text2上,是代码有问题还是其他什么原因,希望各位提供帮助,不甚感激~

解决方案 »

  1.   

    首先你得知道temp到底有没有收到数据
      

  2.   

    If Command2.Caption = "停止接收" Then '首先检查这里,字符串是否与命令按钮显示的相同
        Select Case CommEvent
            Case comEvReceive
                temp = MSComm1.Input
                If MSComm1.InputMode=comInputModeText Then
                    Text2 = StrConv(temp, vbUnicode)
                Else
                    For i = LBound(temp) To UBound(temp)
                        Text2 = Text2 & IIf(Text2 = "", "", " ") & Right("0" & Hex(temp(i)), 2)
                    Next i
                End If
        End Select
    End If