In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Sparks-R-Fun wrote: Jim, You are correct in assessing where your program is going amiss. Your IF... THEN statements are acting as GOTO events. In other words, they cause the program to conditionally jump to a new program location without the expectation of needing to return to the jump point. However, you are expecting your jump locations to act as subroutines and expecting your RETURN statements to take you back to your jump point. [B]Quick Fix:[/B] The fastest fix is the replace your RETURN statements with "GOTO Main". This should make your program perform as expected. [B]Advanced Learning:[/B] At some point you will likely receive great benefit from understanding how to declare and call subroutines. I recommend reading the relevant subroutine section under the Definitions entry of the help file for information on how to properly declare them. Then read about the GOSUB... RETURN statements to learn how to call and return from them. [B]Technical Answer:[/B] What is actually happening now is that you are trying to use RETURN to cause your program execution to continue from a location you did not instruct your program to save. GOSUB saves the address of what should be the next program instruction into a special memory area so that it can RETURN to it later when so instructed. GOTO (and your implied use of GOTO) does not do this as it is assumed that your program should execute a [B]different[/B] code segment as apposed to an [B]additional[/B] code segment. I hope this is helpful. - Sparks ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=200383#m200393 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2007 (http://www.dotNetBB.com)