Code to exit program ? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Code to exit program ?

dadiodadio Posts: 8Member
ok hi....for the same program....if i want to put a footer at the bottom of each page displaying "please press X at any time to return to the main menu" and then of course.....when someone presses the X key...what is the code to call back the main menu procedure?

Comments

  • zibadianzibadian Posts: 6,349Member
    : ok hi....for the same program....if i want to put a footer at the bottom of each page displaying "please press X at any time to return to the main menu" and then of course.....when someone presses the X key...what is the code to call back the main menu procedure?
    :
    You can use GotoXY() to position the text cursor (see help files for more info on GotoXY()).
    The easiest way to handle this is to use a boolean to which indicates that the user pressed the X. Then each procedure should periodically check that boolean and use Exit() to stop.
    A much more efficient way of coding (and much more advanced) is to make your program event driven. This allows the program to call any code at any time.
  • dadiodadio Posts: 8Member
    : : ok hi....for the same program....if i want to put a footer at the bottom of each page displaying "please press X at any time to return to the main menu" and then of course.....when someone presses the X key...what is the code to call back the main menu procedure?
    : :
    : You can use GotoXY() to position the text cursor (see help files for more info on GotoXY()).
    : The easiest way to handle this is to use a boolean to which indicates that the user pressed the X. Then each procedure should periodically check that boolean and use Exit() to stop.
    : A much more efficient way of coding (and much more advanced) is to make your program event driven. This allows the program to call any code at any time.
    :



    wowo thanks...but can u provide code to do this?
    i am not very versed in programming as you realised
  • zibadianzibadian Posts: 6,349Member
    [b][red]This message was edited by zibadian at 2006-12-31 9:52:40[/red][/b][hr]
    : : : ok hi....for the same program....if i want to put a footer at the bottom of each page displaying "please press X at any time to return to the main menu" and then of course.....when someone presses the X key...what is the code to call back the main menu procedure?
    : : :
    : : You can use GotoXY() to position the text cursor (see help files for more info on GotoXY()).
    : : The easiest way to handle this is to use a boolean to which indicates that the user pressed the X. Then each procedure should periodically check that boolean and use Exit() to stop.
    : : A much more efficient way of coding (and much more advanced) is to make your program event driven. This allows the program to call any code at any time.
    : :
    :
    :
    :
    : wowo thanks...but can u provide code to do this?
    : i am not very versed in programming as you realised
    :
    Here's the code to check the boolean:
    [code]
    if HasUserTypedX then
    Exit;
    [/code]
    Insert this line before each read()/readln() and in all loops in procedures, which are called by the main menu. To check if the user typed X, use this code:
    [code]
    if UserInput = 'X' then
    HasUserTypedX := true;
    [/code]
    In the main menu set the HasUserTypedX boolean back to false.
    As you can see, it's not one piece of code, but several, which need to be inserted in several places of your current code.
  • king0deuking0deu Posts: 29Member
    : [b][red]This message was edited by zibadian at 2006-12-31 9:52:40[/red][/b][hr]
    : : : : ok hi....for the same program....if i want to put a footer at the bottom of each page displaying "please press X at any time to return to the main menu" and then of course.....when someone presses the X key...what is the code to call back the main menu procedure?
    : : : :
    : : : You can use GotoXY() to position the text cursor (see help files for more info on GotoXY()).
    : : : The easiest way to handle this is to use a boolean to which indicates that the user pressed the X. Then each procedure should periodically check that boolean and use Exit() to stop.
    : : : A much more efficient way of coding (and much more advanced) is to make your program event driven. This allows the program to call any code at any time.
    : : :
    : :
    : :
    : :
    : : wowo thanks...but can u provide code to do this?
    : : i am not very versed in programming as you realised
    : :
    : Here's the code to check the boolean:
    : [code]
    : if HasUserTypedX then
    : Exit;
    : [/code]
    : Insert this line before each read()/readln() and in all loops in procedures, which are called by the main menu. To check if the user typed X, use this code:
    : [code]
    : if UserInput = 'X' then
    : HasUserTypedX := true;
    : [/code]
    : In the main menu set the HasUserTypedX boolean back to false.
    : As you can see, it's not one piece of code, but several, which need to be inserted in several places of your current code.
    :

    hey Zibadian, could you tell me more about that event-driving? or atleast where can I find information and knowledge aboutt this stuff?
  • zibadianzibadian Posts: 6,349Member
    : : [b][red]This message was edited by zibadian at 2006-12-31 9:52:40[/red][/b][hr]
    : : : : : ok hi....for the same program....if i want to put a footer at the bottom of each page displaying "please press X at any time to return to the main menu" and then of course.....when someone presses the X key...what is the code to call back the main menu procedure?
    : : : : :
    : : : : You can use GotoXY() to position the text cursor (see help files for more info on GotoXY()).
    : : : : The easiest way to handle this is to use a boolean to which indicates that the user pressed the X. Then each procedure should periodically check that boolean and use Exit() to stop.
    : : : : A much more efficient way of coding (and much more advanced) is to make your program event driven. This allows the program to call any code at any time.
    : : : :
    : : :
    : : :
    : : :
    : : : wowo thanks...but can u provide code to do this?
    : : : i am not very versed in programming as you realised
    : : :
    : : Here's the code to check the boolean:
    : : [code]
    : : if HasUserTypedX then
    : : Exit;
    : : [/code]
    : : Insert this line before each read()/readln() and in all loops in procedures, which are called by the main menu. To check if the user typed X, use this code:
    : : [code]
    : : if UserInput = 'X' then
    : : HasUserTypedX := true;
    : : [/code]
    : : In the main menu set the HasUserTypedX boolean back to false.
    : : As you can see, it's not one piece of code, but several, which need to be inserted in several places of your current code.
    : :
    :
    : hey Zibadian, could you tell me more about that event-driving? or atleast where can I find information and knowledge aboutt this stuff?
    :
    Basically event-driven applications are a very short loop, which checks for something to do. In pseudo code:
    [code]
    begin
    repeat
    if Event found then
    HandleEvent
    Do other processes
    until end program
    end
    [/code]
    A working Pascal example is this:
    [code]
    uses
    Crt;

    var
    ch: char;
    i: integer;
    s: string;
    begin
    i := 0;
    s := '';
    repeat
    { Other process: count to 100000 }
    GotoXY(1, 1);
    writeln(i);
    if i > 100000 then
    i := -1
    else
    inc(i);
    { Event: keyboard key press }
    if KeyPressed then
    begin
    ch := ReadKey;
    s := s + ch;
    writeln(s);
    end;
    until ch = 'Q'; { Program end: SHIFT+Q }
    end.
    [/code]
    For more info on event-driven programming see this article: http://en.wikipedia.org/wiki/Event-driven
Sign In or Register to comment.