BBS: Inland Empire Archive Date: 02-05-93 (03:37) Number: 398 From: RAYMOND KEITH Refer#: NONE To: ERIC MAYS Recvd: NO Subj: Data Input Editor Part 2 Conf: (2) Quik_Bas
ExitInputLoop$ = No$ 'In my programs No$ = N Yes$ = Y CALL GPrint2VE(BYVAL InputLin%, BYVAL InputCol%, InputStr$,_ BYVAL TextColr%) 'The above line prints the input string which is currently blank. It uses 'a very fast and handy library routine for graphics mode from Crescent 'Software. For text mode you would need to replace it with Locate #,# 'Color #,# Print InputStr$, etc. In the rest of this code list, when the 'GPrint2VE routine is called it is assumed you will remember this note 'and modify as needed. DO 'Until action which ends input mode. Escape, etc. CALL ShowCursor 'Show mouse pointer DO 'Until a key or mouse button are pressed CALL GetButOrKeyPress 'see part 3 for this routine CursorColumn% = ((InputCol% + CursorPos%) - 2) * 8 'calculate cursor column position. This formula is 'for graphics mode. Text mode might be something like '(InputCol% + CursorPos%) - 1 CursorLine% = InputLin% + CursorLineOffset% 'again this is for graphics mode. Text mode cursor 'line would just be the current line. CALL ClearVE 'Delete this for text mode CALL DrawCursor(CursorColumn%, CursorLine%, CursorWidth%,_ CursorLength%, CursorOnOff%, CurSpeed%) 'see part 3 for information on this routine. It just 'handles the blinking graphics cursor. IF GenInStatMsgCheck% THEN CALL GenInStatMsgs END IF 'This routine will print the status line message 'at the bottom of the screen. Msg depends on the 'current mouse pointer location which is retrieved 'in the GetButOrKeyPress routine. See part 3 for 'an example. LOOP UNTIL HotKey$ <> "" OR Count% > 0 'Here I just loop through the above code until the 'GetButOrKeyPress routine reports that a key or 'mouse button has been pressed. IF CursorOnOff% THEN CALL DrawCursor(CursorColumn%, CursorLine%,_ CursorWidth%, CursorLength%, CursorOnOff%, -1) 'Here if the blinking cursor is on I turn it off. Not 'needed for text mode unless you support mice. CALL HideCursor 'Turn the mouse pointer off IF Count% > 0 THEN ExitInputLoop$ = Yes$ 'If Count% is > than 0 then a mouse button has been 'pressed. I then exit the Input Editor and handle the 'button press as needed. If the button press was not 'valid I'd jump right back into the editor where I 'left off. If it was valid, say the user clicked a 'help button or clear field button, well you get the 'picture. ELSE IF CursorPos% < InputLen% THEN EndOfStr% = 0 'Reset end of field beep SELECT CASE HotKey$ CASE Char1$, Char2$, Char3$, Char4$, GroupFrom$ TO GroupTo$ 'if a valid key has been pressed then... IF EditMode% = 0 THEN 'INSERT MODE MID$(InputStr$, CursorPos%) = LEFT$((HotKey$ + MID$(InputStr$,_ CursorPos%)), InputLen%) ELSE 'OVERSTRIKE MODE MID$(InputStr$, CursorPos%) = HotKey$ END IF CursorPos% = CursorPos% + 1 IF CursorPos% > InputLen% THEN CursorPos% = InputLen% EndOfStr% = EndOfStr% + 1 IF EndOfStr% > 1 THEN CALL Chime(6) END IF 'Here is a check for when the user tries to type past the end of 'of an input area. If the field length is say 10 you only want to 'beep at the user when they try typing the 11th character. This 'bit of code tracks this. Replace the call to Chime(6) with a basic 'BEEP or your own custom noise maker. CALL GPrint2VE(BYVAL InputLin%, BYVAL InputCol%, InputStr$,_ BYVAL TextColr%) 'Just a reminder the above line simply prints the input string. Use 'LOCATE COLOR PRINT etc. CASE LCur$ IF CursorPos% > 1 THEN CursorPos% = CursorPos% - 1 'if the left arrow key was pressed. In my programs I assign the 'keys like arrows, enter, home, end, etc. to variables. LCur$ = 'the two byte scan code for the left arrow key. CASE RCur$ IF CursorPos% < InputLen% THEN CursorPos% = CursorPos% + 1 'if the right arrow key was pressed CASE HomeKey$ CursorPos% = 1 'if the home key was pressed CASE EndKey$ CursorPos% = InputLen% 'if the end key was pressed CASE DeleteKey$ MID$(InputStr$, CursorPos%) = MID$(InputStr$, CursorPos% + 1) + " " CALL GPrint2VE(BYVAL InputLin%, BYVAL InputCol%, InputStr$,_ BYVAL TextColr%) 'if the delete key was pressed CASE Backspace$ IF CursorPos% > 1 THEN CursorPos% = CursorPos% - 1 MID$(InputStr$, CursorPos%) = MID$(InputStr$, CursorPos% + 1)_ + " " CALL GPrint2VE(BYVAL InputLin%, BYVAL InputCol%, InputStr$,_ BYVAL TextColr%) END IF 'if the backspace key was pressed CASE InsertKey$ IF EditMode% = 0 THEN EditMode% = 1 CursorLineOffset% = 0 CursorLength% = 15 ELSE EditMode% = 0 CursorLineOffset% = 14 CursorLength% = 1 END IF 'if the insert key was pressed toggle between insert and overstrike CASE ELSE ExitInputLoop$ = Yes$ 'if any other key is pressed exit the input editor and check it. I 'exit here to check for valid Hotkeys for example. END SELECT END IF LOOP WHILE ExitInputLoop$ = No$ END SUB 'This is the end of the input editor. See part 3 for items noted above. --- DB 1.51/003468 * Origin: R/E Northwest (1:105/224)
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