Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Formatted input PB/CC

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Formatted input PB/CC

    Code:
    #dim all 'inputcc.bas   
    '
    'this posting was some how deleted off forum so it was reposted 3/2/05
    '
    please post comments at: http://www.powerbasic.com/support/pb...ad.php?t=22364 
    '
    
    declare sub inputcc(inputallowed$,mask$,answer$,lastkey$,fillchar%)
    function pbmain&
      dim phone$,amount$
      color 7,1,1
      cls
      print "inputcc (inputallowed$,mask$,answer$,lastkey$,fillchar%)
      print
      print "inputallowed$   keys allowed as input  0-9, a-z, a-z, yn, xx ,aa
      print "mask$           string displayed with embedded chr$(fillchar%)
      print "                mask$ can just be chr$(fillchar%) to fill in a form
      print "answer$         characters typed by user
      print "lastkey$        lastkey user pressed on exit
      print "fillchar%       characters replaced with input
      dim inputallowed$, mask$, answer$,lastkey$, fillchar%
      inputallowed$ = "0123456789"
      mask$ = "phone (___) ___-____"
      fillchar% = asc("_")
      locate 10,1  'where to begin
      call inputcc (inputallowed$,mask$,phone$,lastkey$,fillchar%)
      locate 10,29
      mask$ = "enter amount $ ____.__"
      call inputcc (inputallowed$,mask$,amount$,lastkey$,fillchar%)
      locate 12,1
      print "phone =  "phone$, "amount = "amount$
      waitkey$
    end function
    
    sub inputcc (inputallowed$,mask$,answer$,lastkey$,fillchar%)
        dim inputrow%, inputcolumn%, masklength%, cursorposition%
        if fillchar% = 0 then fillchar% = asc("_")
        inputrow% = cursory
        inputcolumn% = cursorx
        lastkey$ = "
        masklength% = len(mask$)
    startinput:
        cursorposition% = 0
        answer$ = "
        locate inputrow%, inputcolumn%
        print mask$;
        if lastkey$ = chr$(27) then exit sub
    continueinput:
        locate inputrow%, inputcolumn%
        cursorposition% = instr(cursorposition% + 1, mask$ + chr$(fillchar%), chr$(fillchar%))
        locate inputrow%,inputcolumn% + cursorposition - 1   'move right
        if cursorposition% > masklength% then
          gosub findcursorposition
          exit sub
        end if
    getcharacter:
       lastkey$ = waitkey$         'release timeslices while waiting
       if instr(inputallowed$, lastkey$) then
          print lastkey$;
          answer$ = answer$ + lastkey$
          goto continueinput
       end if
       lastkey$ = right$(lastkey$, 1)
       on instr(chr$(8) + chr$(119) + chr$(13) + chr$(27), lastkey$) goto backspace, startinput, enterpressed, startinput
       if cursorposition% <= masklength% then goto getcharacter
    exit sub
    backspace:
       if len(answer$) = 0 then
          goto getcharacter
       else
          locate inputrow%, inputcolumn%
          answer$ = left$(answer$, len(answer$) - 1)
          locate inputrow%,inputcolumn% + cursorposition -1      'move left
          gosub findcursorposition
          print chr$(fillchar%);
          locate inputrow%, cursorx-1
          goto getcharacter
       end if
    findcursorposition:
       cursorposition% = cursorposition% - 1
       locate inputrow%,cursorx-1
       if mid$(mask$, cursorposition%, 1) <> chr$(fillchar%) then goto findcursorposition
    return
    enterpressed:
    end sub
    ------------------




    [this message has been edited by mike doty (edited march 20, 2007).]
    CMD shortcut to open any location:
    %windir%\system32\cmd.exe /k " cd\ & x: & cd x:\xxxx
    Change to run as administrator
    How long is an idea? Write it down.
Working...
X