Code help
                    Hi to all,
in the attached code, when an out of range temperature is entered the message is showed noticed that temperature is out of range but program continues to run, where is my error? Thanks in advance.
                
            in the attached code, when an out of range temperature is entered the message is showed noticed that temperature is out of range but program continues to run, where is my error? Thanks in advance.

                            
Comments
Thanks.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Quit buying all those fixed voltage regulators, and·get an Adjustable Power Supply·for your projects!· Includes an LED testing terminal!
The program continues because you don't tell it to return to the beginning of the program. So even though it will tell you the number is out of range, it is programmed to continue through the code. One solution would be to use subroutines, for example:
Main: DO DEBUG CLS, "Enter temperature in degrees C (Min 18, Max 32)", CR DEBUGIN DEC degrees [b]GOSUB get_constant[/b] [i]' Program continues[/i] LOOP [b]get_constant:[/b] [i]' Subroutine heading[/i] SELECT degrees CASE 18 CmConstant = 2243 [b]GOSUB display_distance[/b] [i]' Program continues, add to each case statement[/i] ... DEBUG CR, "Temperature out of range.", CR, "Enter a different one." [b]RETURN[/b] [i]' Returns to Main to get another temperature value[/i] ... [b]display_distance:[/b] [i]Rest of code continues here[/i]Putting the main routine in a DO...LOOP ensures that the code will get another value each time the program receives a value that is out of the range of temperatures. Then, when the program receives a temperature that's in range, it continues to the "display_distance" subroutine (you can re-name them whatever you like) to get readings from the PING.
For more information on subroutines, look up "GOSUB" in the BASIC Stamp Syntax and Reference Manual.
Hope this helps!
Jessica
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jessica Uelmen
Education Department
Parallax, Inc.
Post Edited (Jessica Uelmen (Parallax)) : 6/1/2009 4:50:26 PM GMT