BBS: Inland Empire Archive Date: 02-10-93 (22:53) Number: 399 From: JIM LITTLE Refer#: NONE To: CASEY PEARSON Recvd: NO Subj: QuickBasic Program # 1/2 Conf: (2) Quik_Bas
CP>I'm working on my third project in class, but I need you'lls help on CP>setting it up. Here is what is asked: "This assignment is designed to CP>provide you with experience in writing higly interactive programs, CP>additional experience in using sequential files and understanding of the CP>relationship between the progrsm in a system. CP>Problem: El Si Si Collegio needs a program to assist the data entry CP>operators in creating the "UPDTRECS.DAT" file. They need an easy to use CP>program that will allow the operators to key the information while it CP>automatically checks for common data entry errors." CP>The screen would erfo look something like this: ..etc.. CP>Now of course since in structured BASIC, Input, Line input cannot be CP>used, INKEY$ is the only valid command to be used. Does anyone have any CP>ideas? I'm don't follow why you can't use Input.. Are you talking about a different type of BASIC, or just the restrictions imposed on you by your class? If the second is true, the following routine may help.. I use it for all my input. Admittedly, the code could be tightened up a bit, but I'm lazy :) This sub has the advantage of returning a flag that tells the calling sub how input was terminated, so the up arrow, down arrow, etc. can be used to move around the screen. Also, a text string longer than the available space may be inputted. Anyway, here it is: SUB CInput (text$, left%, right%, length%, flag%) 'written by Jim Little 'programmed in QBasic ' 'Purpose: Inputs string of text on current line, starting at 'left', and ' continuing to 'right'. If allowed length 'length' is longer than ' space allows, text scrolls to left. ' 'parameters: ' text$ text inputted from keyboard. If text$ is not empty, ' then inputted text added to text$ ' left% left border of input window ' right% right border of input window ' length% maximum length allowed for text$ ' flag% set to cEscape, cUpArrow, cDownArrow, cPageUp, ' cPageDown, or cOK depending on how input was ' terminated. cOk signifies normal termination (with the ' Enter key) ' 'constants: ' c_____ see flag%, above. I used 0 - 5. ' k_____ (____ = Insert, Delete, Home, End, PageUp, PageDown, ' UpArrow, DownArrow, LeftArrow, RightArrow.) ASCII ' values for characters returned by GetStroke for ' extended (grey) keys. I used 201 - 210. ' False 0 ' True NOT False (-1) ' 'subs: ' PrintLine prints a line of text within two borders (left and ' right). ' GetStroke returns one character, from the keyboard. If extended ' key pressed, returns CHR$(k_____) (See k___, above) DIM topletter AS INTEGER 'letter at left of window DIM curletter AS INTEGER 'letter at cursor position DIM finished AS INTEGER 'true if user finished typing line DIM keystroke AS STRING 'user's last keystroke STATIC insert AS INTEGER 'true if insert is on, false otherwise text = RTRIM$(text) 'trim off all extra spaces text = text + CHR$(255) 'null character, so cursor can move one past end of topletter = 1 curletter = 1 finished = False PrintLine 1, text, left, right 'following in case cursor size changes between calls IF insert THEN LOCATE , , , 4, 5 'change cursor size to large block ELSE LOCATE , , , 0, 5 'change cursor size to thin line END IF DO LOCATE , left + curletter - topletter, 1 GetStroke keystroke LOCATE , , 0 IF keystroke = CHR$(kInsert) THEN insert = NOT insert IF insert THEN LOCATE , , , 4, 5 'change cursor size to large block ELSE LOCATE , , , 0, 5 'change cursor size to thin line END IF ELSEIF keystroke = CHR$(kDelete) AND LEN(text) > 1 AND curletter <> LEN(text MID$(text, curletter) = MID$(text, curletter + 1) text = LEFT$(text, LEN(text) - 1) PrintLine topletter, text, left, right ELSEIF keystroke = CHR$(8) AND curletter > 1 THEN text = LEFT$(text, curletter - 2) + RIGHT$(text, LEN(text) - curletter + curletter = curletter - 1 IF curletter < topletter THEN topletter = topletter - 1 END IF PrintLine topletter, text, left, right ELSEIF keystroke = CHR$(kHome) AND curletter > 1 THEN curletter = 1 IF curletter < topletter THEN topletter = 1 PrintLine topletter, text, left, right END IF ELSEIF keystroke = CHR$(kEnd) AND curletter < LEN(text) THEN curletter = LEN(text) IF curletter > topletter + right - left THEN topletter = LEN(text) - right + left PrintLine topletter, text, left, right END IF ELSEIF keystroke = CHR$(kLeftArrow) AND curletter > 1 THEN curletter = curletter - 1 IF curletter < topletter THEN topletter = topletter - 1 PrintLine topletter, text, left, right END IF ELSEIF keystroke = CHR$(kRightArrow) AND curletter < LEN(text) THEN curletter = curletter + 1 IF curletter > topletter + right - left THEN topletter = topletter + 1 PrintLine topletter, text, left, right END IF ELSEIF keystroke = CHR$(kPageUp) THEN flag = cPageUp finished = True ELSEIF keystroke = CHR$(kPageDown) THEN flag = cPageDown finished = True ELSEIF keystroke = CHR$(kUpArrow) THEN flag = cUpArrow finished = True ELSEIF keystroke = CHR$(kDownArrow) THEN flag = cDownArrow finished = True ELSEIF keystroke = CHR$(27) THEN flag = cEscape finished = True ELSEIF ASC(keystroke) >= 32 AND ASC(keystroke) <= 127 AND insert AND LEN(tex >>> Continued to next message
Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET