Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
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.

Anybody know any quit/reset commands?

VHoangVHoang Posts: 3Member
Right now I'm still improvising with a repeat command to repeat the whole program and exit it by a simple write-readln command, it would look something like this:
[size=4]
Uses crt;
Var x: byte;
Begin
Repeat
Clrscr;
Writeln('hello world!');
Write('AGAIN?? (enter 1 to do it, 0 to exit)');
Until(x=0)
End.
[/size]
I want to somehow remove the ugly phrase "enter 1...", like letting the user press "esc" to exit or maybe an exit button and that I click with my mouse (I saw games written with pascal, some were really awesome, and they featured an exit button :P)

Comments

  • quikcarlxquikcarlx Hollywood, FlPosts: 26Member
    As per the Free Pascal Compiler 2.6.0, you can use the [color=Purple][b]Exit[/b][/color] procedure in either a subroutine and in the main program. Below is a possible way to do the input character.
    [code] const
    esc = #27;

    var
    ec : char; {Entry Character }
    .
    .
    .
    ec := readkey;
    case ec of
    esc : begin
    { do something }
    end;
    'y','1' : begin
    { do something else }
    end;
    end;
    [/code]
  • VHoangVHoang Posts: 3Member
    : As per the Free Pascal Compiler 2.6.0, you can use the
    : [color=Purple][b]Exit[/b][/color] procedure in either a subroutine
    : and in the main program. Below is a possible way to do the input
    : character.
    : [code]: const
    : esc = #27;
    :
    : var
    : ec : char; {Entry Character }
    : .
    : .
    : .
    : ec := readkey;
    : case ec of
    : esc : begin
    : { do something }
    : end;
    : 'y','1' : begin
    : { do something else }
    : end;
    : end;
    : [/code]:
    :

    This all seems a bit confusing to me, how many variables will I need for this procedure? What is the difference between
    [code]const esc = 27[/code]
    And [code]const esc = #27[/code]
    What does the # do? Does it indicate a key on the keyboard when used in a const? Also, you wrote
    [code]var ec : char;
    ...
    Ec:= readkey;
    Case ec of
    Esc:begin ... End; [/code]
    So I suppose the esc const have something to do with the keyboard then?

    And I've never used the command 'case' before, is it similar to the if then command? If so then what's the difference?

    I don't understand what this part do:
    [code]'y', '1'
    ...
    ...
    {do something else}
    End; [/code]
    Would you explain everything to me a bit further? I'm still a highshcool student so my knowledge in pascal is very limited please be gentle with me :)
  • VHoangVHoang Posts: 3Member
    Nevermind this one...
Sign In or Register to comment.