Private Sub MSComm1_OnComm()

    Dim InByte() As Byte

    Dim i As Integer

    Dim LineString As String

    Select Case MSComm1.CommEvent

    Case comEvReceive   

        InByte = MSComm1.Input

        If ((InByte(0) And &HE0) = &H0) And _

            ((InByte(1) And &HE0) = &HE0) Then

           

            LineString = Format(Now, "yyyy/mm/dd hh:mm:ss") & " : " _

            & " " & Right$("0" & Hex(InByte(0)), 2) _

            & " " & Right$("0" & Hex(InByte(1)), 2)

            

            Text8.Text = Text8.Text & LineString & vbCrLf

                       

            If ok_cnt < 1000 Then

                ok_cnt = ok_cnt + 1

            Else

                Open ".\Log\Log" & "_" & Format(Now, "yyyymmdd_hhmmss") & ".txt" For Append As #1

                Print #1, Text8.Text

                Close #1

        

                ok_cnt = 1                

                Text8.Text = ""

            End If



        Else

            

            If err_cnt < 1000 Then

                err_cnt = err_cnt + 1

                

            Else

                err_cnt = 1

            End If

        End If

    End Select

    MSComm1.InBufferCount = 0

    

    Label10.Caption = ok_cnt