home *** CD-ROM | disk | FTP | other *** search
- {.HE Program -- Input - Formatted Data Entry Subroutine}
-
-
-
-
-
- {Author - Henry R. Lifton * Version 1.00 2/19/85
- 3159 Jason Drive * Copyright 1985 - Henry R. Lifton
- Bellmore, NY 11710 * May be freely copied and
- (516) 785-3211 Home * distributed except for
- (516) 752-9114 Business * commercial use
-
-
-
-
- Written in Turbo Pascal, Ver. 2.0
-
-
-
-
-
- ALL Suggestions Welcomed
- Questions Answered
- Contributions Accepted }
-
-
-
-
-
-
- { The purpose of this routine is to format the screen and
- prevent it from being corrupted by unprotected input.
- In addition it provides the ability to edit and correct
- fields at will, before sending them to be processed
- by the program. }
-
-
-
-
-
-
- { The routine should be self documenting. Compiling and running
- it will demonstrate its capabilities (also its limitations).
- Just before the procedure 'LoadArray' is more information
- on the variables and their usage. }
-
- {.PA}
-
-
- {The following should be declared in your program - all are global variables}
-
-
-
- {$C-} {Turns off the control character checking -- makes output faster }
-
-
-
-
- type
- Ascii = set of ' '..'~'; { Range of printable characters }
- Entry = string[35]; { String to hold entries - length=longest Entry }
-
-
-
-
- const
- Upper: Ascii = ['A'..'Z',' ']; {Subsets of }
- Lower: Ascii = ['a'..'z',' ']; {Allowable }
- Nums: Ascii = ['0'..'9',' ','.']; {Characters }
- Math: Ascii = ['%'..'/','<'..'>','['..'`','{'..'~'];
- All: Ascii = [' '..'~'];
- Bks = #08; { Backspace Key }
- Cr = #13; {Carriage return }
- Ff = 1; { These constants represent the number of the first and last }
- Lf = 7; { fields in the Entry and will change with each program }
-
-
-
-
- var
- Field: integer; { Field counter }
- Key: array[1..2] of char; { keystroke entered at the keyboard }
- { Allows for function and special keys}
- Ks: char; { The character to print }
- Ret,
- Fini,
- Done: boolean; { True or False indicators }
- Col,Row, { Column and Row }
- CurPos, { Current cursor position }
- PromptCol, { Column for start of prompt }
- Len: array[Ff..Lf] of integer; { Max. length of input field }
- Prompt,Ans: array[Ff..Lf] of Entry; { Array for Prompts & Answers }
- Uc: array[Ff..Lf] of boolean; { Array for setting upper case }
- Allow: array[Ff..Lf] of Ascii; { Defines Allowable char. set }
-
-
- {.PA}
-
-
- { Minor procedures - called often from main procedure }
-
-
-
-
- procedure Bell; {For when something goes wrong}
- begin
- Sound(440);
- Delay(250);
- NoSound;
- end; {Bell}
-
-
-
- procedure Checkfield; { See if field should wrap around }
- begin
- if Field<Ff then Field:=Lf;
- if Field>Lf then Field:=Ff;
- end; { Checkfield }
-
-
-
- procedure Brackets; { Print Entry limiters }
- begin
- GotoXY(Col[Field]-1,Row[Field]);
- Write('[');
- GotoXY(Col[Field]+Len[Field],Row[Field]);
- Write(']');
- end; { Brackets }
-
-
-
- procedure NoBrackets; {Remove Entry limiters }
- begin
- GotoXY(Col[Field]-1,Row[Field]);
- Write(' ');
- GotoXY(Col[Field]+Len[Field],Row[Field]);
- Write(' ')
- end; { NoBrackets }
-
-
-
-
- {.PA}
- { This is the main routine and calls all those above }
-
- procedure GetInput;
-
- begin {GetInput}
- Ret:=false;
- repeat {until Ret}
- Brackets;
- begin {Read the keyboard}
- GotoXY(CurPos[Field],Row[Field]);
- Read(kbd,Key[1]);
- if (Key[1]=chr(27)) or (Key[1]=chr(0)) then
- begin {Read second keystroke}
- Read(kbd,Key[2]);
- case Key[2] of
- #59: begin {Function Key 1 pressed - all Done}
- Done:=true; Ret:=true; Fini:=true;
- end; {Function Key 1 - all Done}
- #72: begin {Move back (up) one field}
- NoBrackets;
- Field:=Field-1;
- end; {Move back}
- #80: begin {Move ahead (down) one field}
- NoBrackets;
- Field:=Field+1;
- end; {Move ahead}
- #75: begin {Cursor Left (backwards) one stroke}
- CurPos[Field]:=CurPos[Field]-1;
- if CurPos[Field] <Col[Field] then
- begin {Back one field}
- CurPos[Field]:=Col[Field]+Length(Ans[Field]);
- Bell;NoBrackets;
- Field:=Field-1;
- end; {Back one field}
- end; {Cursor left}
- #77: begin {Cursor right (ahead) one stroke}
- CurPos[Field]:=CurPos[Field]+1;
- if CurPos[Field] >Col[Field]+Len[Field] then
- begin {Ahead one field}
- CurPos[Field]:=Col[Field]+Length(Ans[Field]);
- Bell;NoBrackets;
- Field:=Field+1;
- end; {Ahead one field}
- end; {Cursor right}
- #82: begin {Insert Key pressed - this Entry o.k.}
- Done:=true;
- Ret:=true;
- end; {Insert Key 1 }
- end; {Case - second keystroke}
- Checkfield; {check for first or last field overlow}
- end; {Read second keystroke}
- Ks:=Key[1]; {Nothing very special so interpret Key[1] }
- case Ks of {check keystroke for other meanings}
- Cr: begin {carriage return}
- NoBrackets;
- Field:=Field+1;
- Checkfield;
- end; {carriage return}
- Bks: begin {Should we backspace}
- if CurPos[Field]<=Col[Field] then Bell else
- begin {backspace}
- delete(Ans[Field],CurPos[Field]-Col[Field],1);
- CurPos[Field]:=CurPos[Field]-1;
- GotoXY(CurPos[Field],Row[Field]);
- Write(' ');
- GotoXY(CurPos[Field],Row[Field]);
- end; {backspace}
- end; {should we backspace}
- end; {Case Statement - Check keystroke}
- {Nothing there? -- must be a letter or number}
-
- {If Uc is true - convert to upper case }
- if Uc[Field] then if Ks in ['a'..'z'] then Ks:=chr(ord(Ks)-32);
- { Now check if it is allowable }
- if Ks in Allow[Field] then
- begin {check length of answer}
- if Length(Ans[Field]) <= Len[Field] then
- if CurPos[Field]-Col[Field]+1>Len[Field] then Bell else
- begin {Write keystroke}
- HighVideo; {Bright screen }
- Write(Ks);
- LowVideo; { Dim Screen }
- delete(Ans[Field],CurPos[Field]-Col[Field]+1,1);
- insert(Ks,Ans[Field],CurPos[Field]-Col[Field]+1);
- CurPos[Field]:=CurPos[Field]+1;
- end; {Write keystroke}
- end; {check length of answer}
- end; { Reading Keyboard }
- until Ret;
- NoBrackets;
- for Field:=Ff to Lf do {Clear entry fields}
- begin
- GotoXY(Col[Field],Row[Field]);
- Write('':Len[Field]);
- end; {Clear entry fields}
- Field:=Ff; {Start at first field}
- end; {GetInput}
-
- { This is the end of the main routine - following is for program use}
- {.PA}
-
- procedure Titles;
-
-
- type
- T = string[80];
-
-
- var
- Aa: integer;
- Title: T;
-
-
- begin
-
- LowVideo;
- Title:='This is the Title Line';aa:=0;
- Aa:= (80-Length(Title)) div 2;
- GotoXY(aa,2);Write(Title);
- Title:='Ins. Key = Next Record -- F1 = All Finished';Aa:=0;
- Aa:= (80-Length(title)) div 2;
- GotoXY(Aa,21);Write(Title);
- Title:='Use Up & Down Arrows to change fields';Aa:=0;
- Aa:= (80-Length(title)) div 2;
- GotoXY(Aa,23);Write(Title);
-
- end; {Titles}
-
- {.PA}
- {Use this procedure to load the array holding the parameters for the entry}
- { PromptCol = Column prompt is to start
- Row = Row of prompt and entry
- Len = Length of input field
- Prompt = Text of prompt
- Col = Column where input is to start (computed automatically)
- CurPos = Current cursor position (internal to the routine)
- Ans = The entry is returned to your program in this variable
- Uc = True or false for converting lower case entry to upper case
- Allow = The set of acceptable characters as defined earlier
- }
-
-
-
-
- procedure LoadArray;
- begin
- for Field:=Ff to Lf do
- begin {do loop}
- case Field OF
- 1:begin
- PromptCol[Field]:=5;Row[Field]:=6;Len[Field]:=25;
- Prompt[Field]:='Last Name ';
- Col[Field]:=PromptCol[Field]+Length(Prompt[Field])+2;
- CurPos[Field]:=Col[Field];
- Ans[Field]:='';
- Uc[Field]:=true;
- Allow[Field]:=upper;
- end;
-
- 2:begin
- PromptCol[Field]:=5;Row[Field]:=7;Len[Field]:=15;
- Prompt[Field]:='First Name ';
- Col[Field]:=PromptCol[Field]+Length(Prompt[Field])+2;
- CurPos[Field]:=Col[Field];
- Ans[Field]:='';
- Uc[Field]:=true;
- Allow[Field]:=upper;
- end;
-
- 3:begin
- PromptCol[Field]:=38;Row[Field]:=7;Len[Field]:=1;
- Prompt[Field]:='Initial ';
- Col[Field]:=PromptCol[Field]+Length(Prompt[Field])+2;
- CurPos[Field]:=Col[Field];
- Ans[Field]:='';
- Uc[Field]:=true;
- Allow[Field]:=upper;
- end;
-
- 4:begin
- PromptCol[Field]:=5;Row[Field]:=8;Len[Field]:=35;
- Prompt[Field]:='Street Address ';
- Col[Field]:=PromptCol[Field]+Length(Prompt[Field])+2;
- CurPos[Field]:=Col[Field];
- Ans[Field]:='';
- Uc[Field]:=false;
- Allow[Field]:=all;
- end;
-
- 5:begin
- PromptCol[Field]:=5;Row[Field]:=9;Len[Field]:=15;
- Prompt[Field]:='City ';
- Col[Field]:=PromptCol[Field]+Length(Prompt[Field])+2;
- CurPos[Field]:=Col[Field];
- Ans[Field]:='';
- Uc[Field]:=false;
- Allow[Field]:=upper+lower;
- end;
-
- 6:begin
- PromptCol[Field]:=35;Row[Field]:=9;Len[Field]:=2;
- Prompt[Field]:='State ';
- Col[Field]:=PromptCol[Field]+Length(Prompt[Field])+2;
- CurPos[Field]:=Col[Field];
- Ans[Field]:='';
- Uc[Field]:=true;
- Allow[Field]:=upper;
- end;
-
- 7:begin
- PromptCol[Field]:=50;Row[Field]:=9;Len[Field]:=5;
- Prompt[Field]:='Zip Code ';
- Col[Field]:=PromptCol[Field]+Length(Prompt[Field])+2;
- CurPos[Field]:=Col[Field];
- Ans[Field]:='';
- Uc[Field]:=true;
- Allow[Field]:=nums;
- end;
-
- end; {doloop}
- end; {case}
- end; {LoadArray}
-
- {.PA}
-
- procedure Prompts;
- begin
- for Field:=Ff to Lf do
- begin
- LowVideo;
- GotoXY(PromptCol[Field],Row[Field]);
- Write(Prompt[Field]) { prompt is from an array }
- end;
- end;{Prompts}
-
- procedure ReDisplay;
- begin
- for Field:=Ff to Lf do
- begin
- GotoXY(Col[Field],Row[Field]+10);
- Write('':Len[Field]);
- GotoXY(Col[Field],Row[Field]+10);
- WriteLn(Ans[Field]);
- end;
- Field:=Ff;
- end; {ReDisplay}
-
-
- {This is the start of the Program}
-
-
- begin
- Titles;
- LoadArray;
- Prompts;
- Done:=false;Fini:=false;
-
- while not Fini do
- repeat
- Field:=Ff;
- GetInput;
- ReDisplay;
- for Field:=Ff TO Lf do {Initialize fields}
- begin
- CurPos[Field]:=Col[Field];
- end; {Initialize fields}
- until Done;
- end. {Fini}
-
-
-
-
- { That's all, Folks }