Private Sub mscomm1_oncomm()
    Dim inByte() As Byte
    Dim i As Integer    Select Case MSComm1.CommEvent
        Case comEvReceive
        inByte = MSComm1.Input
        For i = 0 To UBound(inByte)
        If Len(Hex(inByte(i))) = 1 Then
            strData = strData & "0" & Hex(inByte(i))
        Else
            strData = strData & Hex(inByte(i))
        End If
        Next
        Text1.Text = strData
        '以下写符合通信协议规定的判断代码处理接收数据
        If Mid(strData, 1, 2) = "A5" And Len(strData) >= 66 Then
            dateSj = Mid(strData, 7, 2) & "-" & Mid(strData, 9, 2) & "-" & Mid(strData, 11, 2)       '日期显示
            Text2 = dateSj
            BhSj = Mid(strData, 3, 4)                                                                '检测台编号
            Text15 = BhSj
            timeSj = Mid(strData, 13, 2) & ":" & Mid(strData, 15, 2) & ":" & Mid(strData, 17, 2)     '时间显示
            Text3 = timeSj
            zjhSj = Mid(strData, 19, 4)                                                              '主机号显示
            Text4 = zjhSj
            swsjSj = Mid(strData, 35, 2)                                                             '上网时间
            Text5 = swsjSj & "S"
            gzdlSj = Mid(strData, 39, 2) & "." & Mid(strData, 41, 2)                                 '工作电流
            Text6 = Format(gzdlSj, "0.00") & "A"
            pfdlSj = Mid(strData, 43, 2) & "." & Mid(strData, 45, 2)                                 '排风电流
            Text7 = Format(pfdlSj, "0.00") & "A"
            pfsjSj = Mid(strData, 47, 2) & "." & Mid(strData, 49, 2)                                 '排风时间
            Text8 = Format(pfsjSj, "0.00") & "S"
            TCUSj = Mid(strData, 37, 2)                                                              'TCU状态
            Text9 = TCUSj
            f51Sj = Mid(strData, 27, 4)                                                              '500风压1值
            Text10 = Format(f51Sj, "000") & "Kpa"
            f61Sj = Mid(strData, 31, 4)                                                              '600风压1值
            Text11 = Format(f61Sj, "000") & "Kpa"
            f52Sj = Mid(strData, 59, 4)                                                              '500风压2值
            Text13 = Format(f52Sj, "000") & "Kpa"
            f62Sj = Mid(strData, 63, 4)                                                              '600风压2值
            Text14 = Format(f62Sj, "000") & "Kpa"
            jgSj = Mid(strData, 67, 4)                                                               '结果显示
            Text12 = jgSj
            strData = ""
            
            If TCUSj = 1 Then
            Text9.Text = "A上网B异常"
            Exit Sub
            End If            If TCUSj = 0 Then
            Text9.Text = "A异常B上网"
            Exit Sub
            End If            If TCUSj = 3 Then
            Text9.Text = "A上网B正常"
            Exit Sub
            End If            If TCUSj = 2 Then
            Text9.Text = "A正常B上网"
            Exit Sub
            End If
            
            If jgSj = 0 Then
            Text12 = "正常"
            Exit Sub
            End If
            
            If jgSj > 0 Then
            Text12 = "异常"
            Exit Sub
            End If
        End If
     End Select
     
End Sub
上边是我的代码,我不知道语法怎么用能让最后判断完TCUsj以后还能继续判断jgsj,我现在这样判断完TCUsj就结束了。谢谢

解决方案 »

  1.   


                If TCUSj = 1 Then 
                Text9.Text = "A上网B异常" 
                Exit Sub 
                End If             If TCUSj = 0 Then 
                Text9.Text = "A异常B上网" 
                Exit Sub 
                End If             If TCUSj = 3 Then 
                Text9.Text = "A上网B正常" 
                Exit Sub 
                End If             If TCUSj = 2 Then 
                Text9.Text = "A正常B上网" 
                Exit Sub 
                End If 
                
                If jgSj = 0 Then 
                Text12 = "正常" 
                Exit Sub 
                End If 
                
                If jgSj > 0 Then 
                Text12 = "异常" 
                Exit Sub 
                End If 上面一段建议这样改  select case TCUSj
         case 0
            Text9.Text = "A异常B上网" 
         case 1
            Text9.Text = "A上网B异常" 
         case 2
            Text9.Text = "A正常B上网" 
         case 3
            Text9.Text = "A上网B正常" 
      end select
      If jgSj = 0 Then 
          Text12 = "正常" 
      else
          Text12 = "异常" 
      End If    
      

  2.   

    我刚试了,结果是判断了  If jgSj = 0 Then 
          Text12 = "正常" 
      else
          Text12 = "异常" 
      End If   
    没有判断
    select case TCUSj
         case 0
            Text9.Text = "A异常B上网" 
         case 1
            Text9.Text = "A上网B异常" 
         case 2
            Text9.Text = "A正常B上网" 
         case 3
            Text9.Text = "A上网B正常" 
      end select
      

  3.   


    select case val(TCUSj)
         case 0
            Text9.Text = "A异常B上网" 
         case 1
            Text9.Text = "A上网B异常" 
         case 2
            Text9.Text = "A正常B上网" 
         case 3
            Text9.Text = "A上网B正常" 
      end select
      If val(jgSj) = 0 Then 
          Text12 = "正常" 
      else
          Text12 = "异常" 
      End If    
      

  4.   

    这个解决了,我这么改的。
                  If TCUSj = 0 Then
                Text9.Text = "A异常B上网"
                ElseIf TCUSj = 1 Then
                Text9.Text = "A上网B异常"
                ElseIf TCUSj = 2 Then
                Text9.Text = "A正常B上网"
                ElseIf TCUSj = 3 Then
                Text9.Text = "A上网B正常"
                End If
            If jgSj = 0 Then
                Text12 = "正常"
            Else
                Text12 = "异常"
            End If
            End If
    谢谢你啊,我现在去结贴。