Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4106
Number of posts: 14016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Code to exit program ? Posted by dadio on 31 Dec 2006 at 8:58 AM
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?
Report
Re: Code to exit program ? Posted by zibadian on 31 Dec 2006 at 9:20 AM
: 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.
Report
Re: Code to exit program ? Posted by dadio on 31 Dec 2006 at 9:22 AM
: : 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
Report
Re: Code to exit program ? Posted by zibadian on 31 Dec 2006 at 9:51 AM
This message was edited by zibadian at 2006-12-31 9:52:40

: : : 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:
  if HasUserTypedX then
    Exit;

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:
  if UserInput = 'X' then
    HasUserTypedX := true;

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.
Report
Re: Code to exit program ? Posted by king0deu on 1 Jan 2007 at 8:42 AM
: This message was edited by zibadian at 2006-12-31 9:52:40

: : : : 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:
:
:   if HasUserTypedX then
:     Exit;
: 

: 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:
:
:   if UserInput = 'X' then
:     HasUserTypedX := true;
: 

: 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?
Report
Re: Code to exit program ? Posted by zibadian on 1 Jan 2007 at 8:59 AM
: : This message was edited by zibadian at 2006-12-31 9:52:40

: : : : : 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:
: :
: :   if HasUserTypedX then
: :     Exit;
: : 

: : 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:
: :
: :   if UserInput = 'X' then
: :     HasUserTypedX := true;
: : 

: : 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:
begin
  repeat
    if Event found then
      HandleEvent
    Do other processes
  until end program
end

A working Pascal example is this:
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.

For more info on event-driven programming see this article: http://en.wikipedia.org/wiki/Event-driven



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.