Thanks for the replies. I've tried to include all the necessary code but it didn't stop when I pressed ENTER. The following are my full code :
Private Sub Form1_Load1(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Show()
doloop()
End Sub
Private Sub doloop()
Do
m_bCheckForKeyPress = True
For i = 2 To 3
If m_bKeyPressed = True Then
m_bKeyPressed = False
Exit For
End If
'---------------------------------------------
Application.DoEvents()
Try
'startTime = DateTime.Now.Ticks
With oCP
.Port = i
.BaudRate = 9600
.Parity = Rs232.DataParity.Parity_None
.DataBit = 8
.StopBit = Rs232.DataStopBit.StopBit_1
End With
oCP.Open()
oCP.Write(Encoding.ASCII.GetBytes("strs" & Chr(13)))
' As long as there is information, read one byte at a time and output it.
Try
While (oCP.Read(1) <> -1) 'get byte frm port
WriteMessage(oCP.InputStreamString, False)
End While
Catch exc As Exception
End Try
Dim myStat() As String
myStat = TextBox1.Lines(TextBox1.Lines.Length - 3).Split(" "c)
For o = LBound(myStat) To UBound(myStat) - 1
ListBox2.Items.Add(myStat(o))
Select Case myStat(o)
Case "607", "401", "402"
count += 1
idletime = count
Case "70E", "405", "40A"
count2 += 1
tempsetup = count2
Case "716", "507"
count3 += 1
lotsetuploss = count3
Case "301", "304", "306", "700", "701", "702", "703", "704", "70B", "70D", "710"
count4 += 1
unscheduledDTime = count4
Case "30A", "715"
count5 += 1
speedloss = count5
Case Else
'ignore
End Select
Next
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
oCP.Write(Encoding.ASCII.GetBytes("temp" & Chr(13)))
Try
While (oCP.Read(1) <> -1) 'get byte frm port
WriteMessage2(oCP.InputStreamString, False)
End While
Catch exc As Exception
End Try
actualTemp = TextBox3.Lines(TextBox3.Lines.Length - 8).Split("="c, "€"c) 'split each code in line m
setTemp = TextBox3.Lines(TextBox3.Lines.Length - 7).Split("="c, "€"c)
If actualTemp(1) = 25.0 Then
'if temperature out of band
If actualTemp(1) < (setTemp(1) - 5) Or actualTemp(1) > (setTemp(1) + 5) Then
countTemp += 1
End If
Else
'if temperature out of band
If actualTemp(1) < (setTemp(1) - 3) Or actualTemp(1) > (setTemp(1) + 3) Then
countTemp += 1
End If
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Connection Error")
End Try
'----------------------------
If oCP.IsOpen Then oCP.Close()
Next
m_bCheckForKeyPress = False
Loop
''''''''''''''''''''''''''''''''''''
workbook.Save("c:\test.xls")
Process.Start("c:\test.xls")
End Sub
Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Enter) Then
Else
End If
End Sub
Private Sub Form1_KeyDown(ByVal KeyCode As Integer, ByVal Shift As Integer)
If m_bCheckForKeyPress = True Then
m_bKeyPressed = True
KeyCode = 0
Else
m_bKeyPressed = False
End If
End Sub
Private Sub Form1_Unload(ByVal Cancel As Integer)
'Shut down loop and unload
Me.Close()
End Sub