Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4095
Number of posts: 14004

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

Report
cursor move Posted by red3warlord on 16 Jan 2007 at 9:13 PM
how can i make the cursor move as the program runs by pressing keys on my keyboard?

Report
Re: cursor move Posted by zibadian on 17 Jan 2007 at 12:29 AM
: how can i make the cursor move as the program runs by pressing keys on my keyboard?
:
:
You can use a repeat-until loop, ReadKey(), and GotoXY() for that. Here's the basic layout of the code:
  Set start x, y
  repeat
    GotoXY(X, Y);
    Readkey;
    case KeyRead of
      UpKey: decrease y position
      DownKey: increase y position
      LeftKey: decrease x position
      RightKey: increase x position
    end;
  until EndOfProgram;

I'll leave it to you to write this in the Pascal language. Read the descriptions of Readkey() in the help files, nearly all the other words are variables.
Report
Re: cursor move Posted by red3warlord on 20 Jan 2007 at 8:09 PM
This message was edited by red3warlord at 2007-1-20 20:9:44

: : how can i make the cursor move as the program runs by pressing keys on my keyboard?
: :
: :
: You can use a repeat-until loop, ReadKey(), and GotoXY() for that. Here's the basic layout of the code:
:
:   Set start x, y
:   repeat
:     GotoXY(X, Y);
:     Readkey;
:     case KeyRead of
:       UpKey: decrease y position
:       DownKey: increase y position
:       LeftKey: decrease x position
:       RightKey: increase x position
:     end;
:   until EndOfProgram;
: 

: I'll leave it to you to write this in the Pascal language. Read the descriptions of Readkey() in the help files, nearly all the other words are variables.
:
where should i declare it? in procedure or in the main body?


Report
Re: cursor move Posted by zibadian on 20 Jan 2007 at 10:08 PM
: This message was edited by red3warlord at 2007-1-20 20:9:44

: : : how can i make the cursor move as the program runs by pressing keys on my keyboard?
: : :
: : :
: : You can use a repeat-until loop, ReadKey(), and GotoXY() for that. Here's the basic layout of the code:
: :
: :   Set start x, y
: :   repeat
: :     GotoXY(X, Y);
: :     Readkey;
: :     case KeyRead of
: :       UpKey: decrease y position
: :       DownKey: increase y position
: :       LeftKey: decrease x position
: :       RightKey: increase x position
: :     end;
: :   until EndOfProgram;
: : 

: : I'll leave it to you to write this in the Pascal language. Read the descriptions of Readkey() in the help files, nearly all the other words are variables.
: :
: where should i declare it? in procedure or in the main body?
:
:
:
I would make this the main body of the program. If you do you're starting to write an event-driven program. If this is only a part of the functionality of your program, then I would make this loop into a procedure.
Report
Re: cursor move Posted by red3warlord on 22 Jan 2007 at 7:24 PM
: : This message was edited by red3warlord at 2007-1-20 20:9:44

: : : : how can i make the cursor move as the program runs by pressing keys on my keyboard?
: : : :
: : : :
: : : You can use a repeat-until loop, ReadKey(), and GotoXY() for that. Here's the basic layout of the code:
: : :
: : :   Set start x, y
: : :   repeat
: : :     GotoXY(X, Y);
: : :     Readkey;
: : :     case KeyRead of
: : :       UpKey: decrease y position
: : :       DownKey: increase y position
: : :       LeftKey: decrease x position
: : :       RightKey: increase x position
: : :     end;
: : :   until EndOfProgram;
: : : 

: : : I'll leave it to you to write this in the Pascal language. Read the descriptions of Readkey() in the help files, nearly all the other words are variables.
: : :
: : where should i declare it? in procedure or in the main body?
: :
: :
: :
: I would make this the main body of the program. If you do you're starting to write an event-driven program. If this is only a part of the functionality of your program, then I would make this loop into a procedure.
:
thank you for your help.... at least, my pain lessened down....
so, how could i connect it to declare this code?
is it a procedure or a function?


from red3warlord with gratitude.....


Report
Re: cursor move Posted by zibadian on 22 Jan 2007 at 11:31 PM
: : : This message was edited by red3warlord at 2007-1-20 20:9:44

: : : : : how can i make the cursor move as the program runs by pressing keys on my keyboard?
: : : : :
: : : : :
: : : : You can use a repeat-until loop, ReadKey(), and GotoXY() for that. Here's the basic layout of the code:
: : : :
: : : :   Set start x, y
: : : :   repeat
: : : :     GotoXY(X, Y);
: : : :     Readkey;
: : : :     case KeyRead of
: : : :       UpKey: decrease y position
: : : :       DownKey: increase y position
: : : :       LeftKey: decrease x position
: : : :       RightKey: increase x position
: : : :     end;
: : : :   until EndOfProgram;
: : : : 

: : : : I'll leave it to you to write this in the Pascal language. Read the descriptions of Readkey() in the help files, nearly all the other words are variables.
: : : :
: : : where should i declare it? in procedure or in the main body?
: : :
: : :
: : :
: : I would make this the main body of the program. If you do you're starting to write an event-driven program. If this is only a part of the functionality of your program, then I would make this loop into a procedure.
: :
: thank you for your help.... at least, my pain lessened down....
: so, how could i connect it to declare this code?
: is it a procedure or a function?
:
:
: from red3warlord with gratitude.....
:
:
:
As I have said above it can be a procedure or the main program body. Only use a function if the code returns a clear result. Since this code doesn't return a result it shouldn't be a function.
Report
Re: cursor move Posted by red3warlord on 22 Jan 2007 at 11:41 PM
: : : : This message was edited by red3warlord at 2007-1-20 20:9:44

: : : : : : how can i make the cursor move as the program runs by pressing keys on my keyboard?
: : : : : :
: : : : : :
: : : : : You can use a repeat-until loop, ReadKey(), and GotoXY() for that. Here's the basic layout of the code:
: : : : :
: : : : :   Set start x, y
: : : : :   repeat
: : : : :     GotoXY(X, Y);
: : : : :     Readkey;
: : : : :     case KeyRead of
: : : : :       UpKey: decrease y position
: : : : :       DownKey: increase y position
: : : : :       LeftKey: decrease x position
: : : : :       RightKey: increase x position
: : : : :     end;
: : : : :   until EndOfProgram;
: : : : : 

: : : : : I'll leave it to you to write this in the Pascal language. Read the descriptions of Readkey() in the help files, nearly all the other words are variables.
: : : : :
: : : : where should i declare it? in procedure or in the main body?
: : : :
: : : :
: : : :
: : : I would make this the main body of the program. If you do you're starting to write an event-driven program. If this is only a part of the functionality of your program, then I would make this loop into a procedure.
: : :
: : thank you for your help.... at least, my pain lessened down....
: : so, how could i connect it to declare this code?
: : is it a procedure or a function?
: :
: :
: : from red3warlord with gratitude.....
: :
: :
: :
: As I have said above it can be a procedure or the main program body. Only use a function if the code returns a clear result. Since this code doesn't return a result it shouldn't be a function.
:
now i get it....
this had a very great rev\levance of what my assignnment is!

my instructor wanted me to make a program that will make the cursor move to a certain object, say for example, a character. when the cursor was moved to that character, it will look like a character with a textbackground.... how is it?
Report
Re: cursor move Posted by Phat Nat on 23 Jan 2007 at 7:57 PM
: : As I have said above it can be a procedure or the main program body. Only use a function if the code returns a clear result. Since this code doesn't return a result it shouldn't be a function.
: :
: now i get it....
: this had a very great rev\levance of what my assignnment is!
:
: my instructor wanted me to make a program that will make the cursor move to a certain object, say for example, a character. when the cursor was moved to that character, it will look like a character with a textbackground.... how is it?
:

If this part of your assignment is just one section, then put it into a PROCEDURE, otherwise, just put it all into your main area.
First off, I would make a procedure that displays your background. Whatever you want on the screen that does not change.
Perhaps your screen will display something like this:
First Name: ____________  Last Name: ________________
       Age: ___           Birthdate: _______________

1           12            20         31

The numbers underneath wouldn't be shown, but are there to show that the first set of lines is diplayed 12 characters in and the second set of lines is 31 characters in. These are important. Also, we have two rows.

So we would call our procedure to show this on the screen. This can either be in our main loop or just called once at the start. In our main loop, we would first want to fill in anything that would have been typed in. Use another procedure for this. I will call it ShowData.
ShowData will just use four GotoXY() and Write() to write each variable (eg. FName,LName,Age,BirthDate) in the proper location.

Next inside the loop you would want to display the cursor, then wait for a keypress and determine whether it is an arrow key or a letter/number. a CASE statement would work well here:
Key := Readkey;
CASE Key Of
 #0 : Begin {Extended Keys aka Arrows/Function Keys/etc }
           Key := ReadKey;
           CASE Key Of
            #72 : If Y > 1 Then Y := Y - 1;
            #75 : If X > 1 Then X := X - 1;
            #77 : If X < 2 Then X := X + 1;
            #80 : If Y < 2 Then Y := Y + 1;
           End;
      End;
 #8 : If Length(CurrentStr) > 0 Then Delete(CurrentString,Length(CurrentStr),1);
 'A'..'Z',
 'a'..'z',
 '0'..'9' : CurrentStr := CurrentStr + Key;
END;


This would handle key input as well as arrow movement. When you display the cursor before this, you would just use GotoXY(12+X*19,Y+1);
This way, when X = 0, 12+0*19=12, so your cursor would move to 12,Y+1 and when X = 1, 12+1*19=31, so your cursor would move to 31,Y+1. Note that this is where our two lines start on the screen (19 being the space between the start of the first and second set).

From here, you would just use the STRING variable CurrentStr to set whatever variable is currently selected.
For ease, I would recommend you just store all your String Variables into an array (in this case 2x2) so that you can just use X & Y to set the string.
VAR
   DataStr : Array[0..1,0..1] Of String; {0,0=FName 1,0=LName, 0,1=Age 1,1=B/D }

Instead of the above lines, you would replace them with:
 #8 : If Length(DataStr[X,Y]) > 0 Then Delete(DataStr[X,Y],Length(DataStr[X,Y]),1);
 'A'..'Z',
 'a'..'z',
 '0'..'9' : DataStr[X,Y] := DataStr[X,Y] + Key;


Any questions, just ask,
Phat Nat




 

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.