Editline by tlo20th Apr 2006 21:54
|
---|
Summary A function to replace the INPUT in most Basic programming languages. It provides more control over the response. The code will allow for further modification to restrict the respon Description There are four parameters to pass to the function, x, y position of where you want to place the prompt for the responce, the prompt and finally the limit to the number responce characters. Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com rem ======================================================== rem EditLine function for controlling data input explicitly rem ======================================================== rem Lee Privett started 20th April 2006, idea from Qbasic rem code from early 90s called editline$ I think. rem ======================================================== cls print "EditLine test 1" print print "give me an answer, please" set text opaque Print EditLine(150,175,"Don't use more than 10 characters",10) wait 10000 end function EditLine(xpos,ypos,prompt$,m) remstart ========================================================= locate on the screen x,y position for printing the prompt cpos for current cursor x position m is the maximum text allowed in the response K the key being pressed xpos & ypos are initial values for the prompt mpos is the maximum x position for the text entry fpos is the fixed start point for input text cypos is the character y position ========================================================= remend prompt$=prompt$+" " cpos=xpos+(len(prompt$)*8) mpos=xpos+((len(prompt$)+m)*8) cypos=ypos+11 char=0:txt$="" fpos=cpos rem ============================== rem print the the propmt at the rem appropriate cursor position rem add a space before the reponse rem and then draw the cursor rem ============================== text xpos,ypos, prompt$ gosub DrawCursor Do rem =============================== rem check for the key to be pressed rem =============================== while K=0:K=asc(inkey$()):endwhile rem =================== rem check for Enter key rem =================== if K=13 then exit rem =================== rem check for backspace rem =================== if K=8 cpos=cpos-8 txt$=left$(txt$,len(txt$)-1) else txt$=txt$+chr$(k) if len(txt$)>m txt$=left$(txt$,m) else cpos=cpos+8 endif endif rem ===================================== rem check that cursor position is no more rem than maximum and no less than zero rem ===================================== if cpos<fpos then cpos=fpos if cpos>mpos then cpos=mpos text fpos,ypos,txt$+" " gosub DrawCursor K=0 L=1 rem ====================================== rem check for the key press to be released rem ====================================== while L<>0:L=asc(inkey$()):endwhile Loop endfunction txt$ remstart ==================================== Here we have the begining of the subroutine used for commonly called actions within the function ==================================== remend DrawCursor: line cpos,cypos,cpos+7,cypos return |