How to wait for a value until it performs the next syntax in VB.NET?
<p>I am obtaining height data from my sensor and here is my code:</p>

<pre><code>If Sensor1 = 5 Or Sensor1 = 6 Or Sensor1 = 7 Then
   If Sensor1 &gt;= 13 Then
      flagCtr1 = 1
   End If
ElseIf Sensor1 = 8 Or Sensor1 = 9 Then
   If Sensor1 &gt;= 13 Then
      flagCtr1 = 2
   EndIf
ElseIf Sensor1 = 10 Then
   If Sensor1 &gt;= 13 Then
      flagCtr1 = 3
   End If
End If
</code></pre>

<p>Basically what I want to happen is, for example, when my sensor detected the height 7, it will wait for the value greater than or equal 13 before it performs the flagCtr = 1. I tested this code and nothing happens. </p>

<p>This is my dilemma. This is an example of how I read the height where 15 is the height where there is no object placed below the sensor</p>

<p>15<br>
15<br>
15<br>
7 - object was placed<br>
7<br>
7<br>
7<br>
7<br>
8 - object is being removed<br>
15<br>
15<br>
15<br></p>

<p>everytime I will remove the object it goes to a certain number that is also in one of the conditions. My problem is the latest height data is being read not the data that was read at a time interval. So what I want to do is that I will wait for the sensor to go back to the value greater than or equal 13 before it performs the next instruction.</p>

<p>It's like this, if I detected 7 I want to disregard the other values I read and wait for value that is >=13 </p>

<p>Sorry for a long post, I really need help, this is my thesis. Thank you so much</p>

<p><strong>EDIT1:</strong><Br></p>

<p>how i read my data from my sensors</p>

<pre><code>AxWinsock1.GetData(strData)
for ctr = 0 To UBound(strData)
tstring = tstring + Chr(strData(ctr))
If DisconnectF1=0 Then
If tstring Like "*DATA_*_OK*" Then
Dim parsedStr() As String = Split(tsring,"_")
Sensor1 = parsedSTR(1) : Sensor2 = parsedSTR(2)
Sensor3 = parsedSTR(3) : Sensor4 = parsedSTR(4)
</code></pre>

<p>this what my arduino sends me:
DATA_15_15_15_15_OK</p>

<p><strong>EDIT2:</strong><br></p>

<p>For those who still have problems with the correct solution just make previousState global.</p>