'=========================================================================== ' Subject: EDIT/INPUT STRING Date: 11-09-95 (11:16) ' Author: Alexander Podkolzin Code: PB ' Origin: app@sbank.e-burg.su Packet: TEXT.ABC '=========================================================================== '------------------------------ Demo here ---------------------------------- DEFINT a-z CLS COLOR 0,7 LOCATE 25,1 PRINT " You can use Backspace-,Ins-,Home-,Del-,End- keys and arrow keys. "; s$=InputStr$("I am a string, edit me, please.",3,10,40,15,4) COLOR 14,1 LOCATE 12,10 PRINT s$ END '--------------------------------------------------------------------------- 'ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ '³ FUNCTION : InputStr$ ³ '³ CALL : s$ = InputStr$(Ed$,y%,x%,n%,textcolor%,backcolor%) ³ '³ Where : Ed$ - string to edit, ³ '³ : y%,x% - place to edit/input string from, ³ '³ : n% - number of characters to edit/input. ³ '³ RETURNS : edit/input string, or null-string, if is pressed. ³ '³ AUTHOR : Alexander Podkolzin (app@sbank.e-burg.su). ³ 'ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ' Source code is formatted by my program "PBB". '--------------------------------------------------------------------------- ' FUNCTION InputStr$(Ed$,y%,x%,n%,textcolor%,backcolor%) ' STATIC Ins% ' Switcher of Ins-mode. ' Enter$ = CHR$(13) ' List of keys, we need in Esc$ = CHR$(27) ' our function. BcSp$ = CHR$( 8) ' Ins$ = CHR$(0,82) ' Equals to CHR$(0)+CHR$(82) Home$ = CHR$(0,71) ' Del$ = CHR$(0,83) EndKey$ = CHR$(0,79) LeftKey$ = CHR$(0,75) RightKey$= CHR$(0,77) ' OldX% = POS(0) ' As well-bred programmers, :) OldY% = CSRLIN ' we have to save screen parameters. OldColor% = pbvScrnTxtAttr ' Internal PB variables: color, Vis%=pbvCursorVis ' coursor is visiable (TRUE or FALSE), Sl1%=pbvCursor1 ' top line of cursor, Sl2%=pbvCursor2 ' bottom line. ' Ptr% = x% ' Current cursor position. COLOR textcolor%,backcolor% ' Colors we'll use in our function. LOCATE y%,x% PRINT Ed$ ' Edit$=GetString$(y%,x%,n%) LOCATE y%,x% PRINT Edit$ DO ' Main loop: IF Ptr%x%+n%-1 THEN ' the Ptr%=x%+n%-1 ' cursor position. ITERATE LOOP END IF IF Ins%=0 THEN LOCATE y%,Ptr%,1,7,8 ' Usual cursor ELSE ' LOCATE y%,Ptr%,1,5,8 ' "Ins" cursor END IF WHILE NOT INSTAT: WEND s$ = INKEY$ $IF 1 '---------------------------------------------------------------- ' ' This < $IF...$ENDIF > block is for Russian PB-users only, as INKEY$ ' does not distinguish lowercase Russian character "à". (PB3.0) ' IF LEN(s$)=2 AND ASC(LEFT$(s$,1))=0 AND ASC(RIGHT$(s$,1))=0 THEN s$=CHR$(224) END IF ' $ENDIF '---------------------------------------------------------------- SELECT CASE s$ CASE Esc$ InputStr$="" EXIT LOOP CASE Enter$ InputStr$=RTRIM$(GetString(y%,x%,n%)) EXIT LOOP CASE Ins$ Ins% = Ins% XOR 1 ITERATE LOOP CASE Home$ Ptr%=x% ITERATE LOOP CASE EndKey$ Ptr%=x%+LEN(RTRIM$(GetString(y%,x%,n%))) ITERATE LOOP CASE LeftKey$ DECR Ptr% ITERATE LOOP CASE RightKey$ INCR Ptr% ITERATE LOOP CASE Del$ m%=Ptr%-x% k%=x%+n%-Ptr% Edit$=GetString$(y%,x%,m%)+GetString$(y%,Ptr%+1,k%) CASE BcSp$ ' Exception! DECR Ptr% ' IF Ptr%