: : 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