Computer Science Canada How to make a quit button. |
| Author: | atal [ Sat Sep 24, 2011 3:25 pm ] |
| Post subject: | How to make a quit button. |
Hi guys i have a question. What codding do i need to use to make a quit button. I have been searching around and did not find one that would work, i tried playing around with chars (INPUT_KEY_DOWN) and stuff like that with no success. Srry if this question has already been answered but i could not find it thanks in advance. |
|
| Author: | Insectoid [ Sat Sep 24, 2011 4:15 pm ] | ||
| Post subject: | RE:How to make a quit button. | ||
You'll need a boolean variable to record if the quit button has been pressed. At the bottom of your loop, check if your variable is true (meaning 'quit' has been pressed) and if so, exit the main loop. There are a number of tutorials available on creating buttons, so I won't explain that. the basic premise is,
Alternatively, you can use the 'quit' keyword which terminates the program, but it tells Windows that the program failed/crashed/whatever instead of terminating gracefully. |
|||
| Author: | atal [ Sat Sep 24, 2011 4:29 pm ] | ||
| Post subject: | Re: RE:How to make a quit button. | ||
Insectoid @ Sat Sep 24, 2011 4:15 pm wrote: You'll need a boolean variable to record if the quit button has been pressed. At the bottom of your loop, check if your variable is true (meaning 'quit' has been pressed) and if so, exit the main loop. There are a number of tutorials available on creating buttons, so I won't explain that.
the basic premise is,
Alternatively, you can use the 'quit' keyword which terminates the program, but it tells Windows that the program failed/crashed/whatever instead of terminating gracefully. im sorry (im pretty new at this) but i don't understand what you mean. And i dont want to create a compicated button (yet) i just want it to be like when the use presses a button such as Q the program will terminate |
|||
| Author: | Tony [ Sat Sep 24, 2011 5:42 pm ] |
| Post subject: | RE:How to make a quit button. |
There is essentially just one way to terminate a program -- have to execution flow (current line being run) get to the very end of the program. quit gets there really fast by throwing an exception (TIL that Turing has exceptions; @Insectoid documentation suggests that you could set the exit code to be that of a "success"). Another alternative is to handle loop terminations yourself through a series of exit conditions. It really depends on the control flow of your program. |
|
| Author: | atal [ Sun Sep 25, 2011 11:38 am ] | ||
| Post subject: | Re: RE:How to make a quit button. | ||
Ok so i found this in the tutorial section.
When i add this to my program there is a problem. The problem is that the program uses the user to input a number and what i did is wrote press q to quit. so when i press q it just shows up in were the number should be entered. if i hit enter it syas invalid integer entered. |
|||
| Author: | Tony [ Sun Sep 25, 2011 1:02 pm ] |
| Post subject: | RE:How to make a quit button. |
we have tutorials on loops linked to from The Turing Walkthrough |
|