'===========================================================================
' Subject: Input for PBCC/QB                  Date: 06-14-02 (  :  )       
'  Author: Fred Buffington                    Code: PBCC,QB,PB             
'  Origin: oasys@sbcglobal.net              Packet: PBCC.ABC
'===========================================================================
----------------------------------------------------------
'Fred Buffington - http://thunder.prohosting.com/~oasys
'Here is a simple Text input routine that can be used in 
'PBcc or QB and probably PBdos. 
 
'It includes a PBmain for testing purposes and to show  
'sample calling sequence. 
 
 $COMPILE EXE 
 
 DECLARE FUNCTION Linput(xpos%,ypos%,L%,df$) AS STRING 
'------------------------------------------------ 
'Linput input routine print brackets around input 
'L% is length allow for the input routine 
'xpos,ypos initial position on screen 
'df$ is the default value 
'------------------------------------------------ 
 FUNCTION PBMAIN() 
   CONSOLE SCREEN 26,80 
 
   dflt$="TEST" 
   COLOR 15,1 
   CLS 
   xvar$=linput(5,10,5,dflt$) 
 
   LOCATE 12,5:PRINT xvar$;"<here" 'test to show result 
   WHILE INKEY$="":WEND 
 END FUNCTION 
 
 FUNCTION Linput(x%,y%,L%,df$) AS STRING 
   LOCAL del$,lft$,rit$,zend$,hom$ 
 
   del$=CHR$(0)+CHR$(83)  'delete key 
   Lft$=CHR$(0)+CHR$(75)  'left arrow 
   rit$=CHR$(0)+CHR$(77)  'right arrow 
   zend$=CHR$(0)+CHR$(79) 'end key 
   hom$=CHR$(0)+CHR$(71)  'home key 
   position%=0 
'   LOCATE y%,x%-1:PRINT "[";SPACE$(L%);"]"; 
'  above can be used to put brackets around the input 
   var$=df$ 
   LOCATE y%,x%:PRINT var$; 
   LOCATE y%,x% 
   DO 
 
       xinp$ = INKEY$ 
 
'checkmouse here 
 
       IF xinp$=zend$ THEN position%=l%-1 
 
       IF xinp$=Hom$ THEN position%=0 
 
       IF xinp$=lft$ THEN xinp$=CHR$(8) 'making 8 nondestructive 
 
       IF xinp$>CHR$(30) THEN 
              IF position%+1>LEN(var$) THEN 
 
                  var$=var$+xinp$:position%=position%+1 
              ELSE 
                  MID$(var$,position%+1,1)=xinp$:position%=position%+1 
 
              END IF 
 
        END IF 
 
        IF xinp$=CHR$(8) THEN 
 
'if you want descructive backspace then set xinp$ = del$ and rem position%=position%-1 
 
             position%=position%-1 
 
             IF position%<0 THEN position%=0 
 
        END IF 
 
        IF xinp$ = del$ THEN 
 
            IF position%>0 THEN 
 
               var$=MID$(var$,1,position%)+MID$(var$,position%+2) 
 
            ELSE 
 
                 IF LEN(var$)>1 THEN 
 
                    var$=MID$(var$,2):position%=0 
 
                 ELSE 
  
                    var$="":position%=0 
 
                 END IF 
 
            END IF 
 
        END IF 
 
        IF xinp$=rit$ THEN position%=position%+1 
 
        IF position%>=L% THEN position%=L%-1 
 
        IF xinp$<>"" THEN LOCATE y%,x%:PRINT SPACE$(L%);:LOCATE y%,x%:PRINT var$;:LOCATE y%,x%+position%:CURSOR ON 
 
   LOOP UNTIL xinp$=CHR$(13) OR xinp$=CHR$(27) 
   linput=var$ 
 END FUNCTION 
