Dim bb As Integer
     Dim cc As String
     Dim newStr As Variant
     
     Dim var As Variant
     
     var = MSComm1.Input 
    bb = AscW(Mid(var, 11, 1))上面是部分代码,我是要实现从设备里读出数据,并把读出的数做加或减等数据运算.上面使用ASC时只能在0-127之前做加减运算,128-255间的数被读出后如何转换成能进行算术运算的值.

解决方案 »

  1.   

    LZ:须按2进制方式接收:
    Option Explicit
        Dim strData As StringPrivate Sub Form_Load()
        MSComm1.Settings = "9600,N,8,1"
        MSComm1.RThreshold = 1
        MSComm1.InputMode = comInputModeBinary
        MSComm1.PortOpen = True
    End SubPrivate Sub MSComm1_OnComm()
        Dim BytReceived() As Byte
        Select Case MSComm1.CommEvent
            Case 2
                MSComm1.InputLen = 0
                BytReceived() = MSComm1.Input
                Dim i As Integer
                For i = 0 To UBound(BytReceived)
                    If Len(Hex(BytReceived(i))) = 1 Then
                        strData = strData & "0" & Hex(BytReceived(i))
                    Else
                        strData = strData & Hex(BytReceived(i))
                    End If
                Next
                '按通信协议写接收数据处理代码
         End Select
    End Sub接收的BYTE数组转换为16进制字符串形式,待按通信协议进行数据处理.