Error in Do Loop

headingwest

Member
Licensed User
Longtime User
Hi,

I'm getting some strange errors. Can someone assist in what's wrong with this code...

Error:
B4X:
Parsing code.                           0.02
Compiling code.                         Error
Error compiling program.
Error description: Object reference not set to an instance of an object.
Occurred on line: 428
Do 
Word: do

Code (error on the word "Do") :
B4X:
Sub btnLeft_Click
   btnStop_Click
   NewServiceMessage("Turning Left " , "", 1, 1000)
   
   Dim lCurrentHeading As Long 
   Dim lTargetHeading As Long
   Dim lAdjustedHeading As Long    
   
   lTargetHeading = lCurrentHeading - lTurnDegrees    
   If lTargetHeading < 0 Then 
      lTargetHeading = lTargetHeading + 360
   End If
   
   Do 
      lCurrentHeading = Heading
      
      If lTargetHeading > (360 - lTurnDegrees) AND lCurrentHeading < lTurnDegrees Then
         lCurrentHeading = lCurrentHeading + 360
      End If
      
      pinMotor4.DutyCycle = CurrentDutyCycle
      pinMotor3.DutyCycle = CurrentDutyCycle
   Loop While (lCurrentHeading < lTargetHeading)
   
End Sub
 

stevel05

Expert
Licensed User
Longtime User
Your syntax for the loop is incorrect, look here
 
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
B4A don't support
B4X:
Do
.....
Loop While

You need to use:
B4X:
Do While
.....
Loop

Sergio
 
Upvote 0
Top