home *** CD-ROM | disk | FTP | other *** search
-
- '*************** "PANEL" SUB-PROGRAMS for QuickBASIC!!! *********************
- ' Not worthy of applause or money, these were written in a hurry to solve a
- 'problem. You may find some of it handy (especially instring!). I tried to
- 'generalize, but I know there are many improvements that could be made.
-
- common shared promptfg%,promptbg%,highfg%,fieldfg%,fieldbg%
- ' the colors set by "call panelcolor(..."
-
- sub panelcolor( color1%,color2%,color3%,color4%,color5%) static
- ' this subprogram is called to set up the colors for an input panel
- promptfg% = color1%
- promptbg% = color2%
- highfg% = color3%
- fieldfg% = color4%
- fieldbg% = color5%
- end sub
-
- sub promptdisplay(screen$(2), quantity%) static
- ' this subroutine will display all the prompts from the two-dimensional
- 'string array defined at the start of the program.
- 'NOTE : "quantity" must be the size of the first dimension (in other
- 'words, in the demo, it is actually quantity minus one!)
- color promptfg%,promptbg%
- for num = 0 to quantity%
- locate val(screen$(num,1)),val(screen$(num,2))
- print screen$(num,0);
- next
- end sub
-
-
- sub fielddisplay(screen$(2), quantity%) static
- ' this subroutine will display all the input fields from the two-dimensional
- 'string array defined at the start of the program.
- 'NOTE : "quantity" must be the size of the first dimension (in other
- 'words, in the demo, it is actually quantity minus one!)
- color fieldfg%,fieldbg%
- for num = 0 to quantity%
- locate val(screen$(num,1)),val(screen$(num,2)) + len(screen$(num,0))+1
- print screen$(num,4);spc(val(screen$(num,3))-len(screen$(num,4)));
- next
- end sub
-
-
- sub fieldentry(screen$(2),quantity%) static
- ' This subprogram will handle the entry of strings into all the fields
- 'of the two-dimensional string array that makes up the info-input screen.
- '
- color promptfg%,promptbg%
- num = 0
- while (num < quantity%+1) AND (num > -1)
- locate val(screen$(num,1)), val(screen$(num,2)) ' first, highlight the prompt
- color highfg%
- print screen$(num,0);
- locate val(screen$(num,1)), val(screen$(num,2))+len(screen$(num,0))+1
- color fieldfg%,fieldbg%
- getstring: mykey$ = "Y" ' we DO want function keys
- call instring( screen$(num,4), cint(val(screen$(num,3))), mykey$)
- locate val(screen$(num,1)),val(screen$(num,2)) ' un-highlight the prompt
- color promptfg%,promptbg%
- print screen$(num,0);
- if len(mykey$) = 2 then ' must be a function key
- if (right$(mykey$,1) = chr$(72)) then
- if num > 0 then
- num = num - 1
- else num = quantity%
- end if
- elseif (right$(mykey$,1) = chr$(80)) then
- if num < quantity% then
- num = num + 1
- else num = 0
- end if
- else
- goto getstring ' must not be a legal function key!
- end if
- elseif mykey$ = chr$(13) then
- if num < quantity% then
- num = num + 1
- else num = 0
- end if
- elseif mykey$ = chr$(27) then
- num = quantity%+1 '(FORCE THE EXIT)
- end if
- wend
- end sub
-
-
- sub instring( strg$, limit%, lastkey$) static
- ' This subprogram will serve as a replacement for BASICA's Input command
- 'for strings. The parameters are : strg$ = string for user input/editting
- ' limit = max. number of characters allowed
- ' lastkey$ = for instring to return the
- ' last key pressed (only if
- ' lastkey$ contains "Y" on entry)
- ' Note that if strg$ contains a string on entry, the user may edit the
- 'string using simple editing functions (cursor movement, DEL, BKSP).
- ' Also, unlike BASIC's "Input", all normal characters are legal.
- 'When this subprogram returns, the cursor will be ON, and positioned at the
- 'last location at which anything was typed.
- ' If lastkey$ contains the letter "Y" upon entry, this subprogram will
- 'exit when the following keys are hit: return, up arrow, down arrow, HOME,
- 'END, and escape. The key used to exit will be returned to the caller in
- 'Lastkey$ so that the caller may take appropriate action (go to the next
- 'field, quit the screen, etc.)
-
- ' IMPORTANT: The second parameter to this subprogram MUST be an integer!!!!
- 'If it is not an integer, you may have a catastrophic crash! If you can
- 'think of a way that this suprogram can determine the type of variable passed,
- 'you could add that code. (And please let me know!)
-
- if lastkey$ = "Y" then ' should we leave on function keys?
- functs = 1
- else
- functs = 0 ' 0 = FALSE
- end if
-
- startcol = pos(0) ' column in which we start
- print strg$; spc(limit% - len( strg$)); ' print the string and clear all
- ' needed space
-
- if limit% > len(strg$) then ' current position will be at end of string+1,
- curpos = len(strg$)+1 ' unless field is full
- else
- curpos = 1
- end if
-
- locate ,startcol+curpos-1,1 'start at end of string, and turn on cursor!!
- tmp$ = ""
-
- while tmp$ <> chr$(13) ' the main loop waits for a carriage return
- tmp$ = ""
- while len(tmp$) = 0 ' len will be 1 for characters, 2 for function keys
- tmp$ = inkey$
- wend
- if len(tmp$) = 2 then ' function key code
- if functs then
- if right$(tmp$,1) = chr$(75) then ' left cursor?
- if curpos > 1 then
- curpos = curpos -1
- end if
- elseif right$(tmp$,1) = chr$(77) then ' right cursor?
- if curpos < len( strg$) + 1 then ' dont move more than 1 past end
- curpos = curpos + 1
- end if
- elseif right$(tmp$,1) = chr$(71) then ' HOME key?
- curpos = 1
- elseif right$(tmp$,1) = chr$(79) then ' END key?
- curpos = len(strg$)+1
- elseif right$(tmp$,1) = chr$(83) then ' DEL key?
- if (len(strg$) > 0) and (curpos <= len(strg$)) then
- strg$ = left$(strg$, curpos-1) + right$(strg$,len(strg$)-curpos)
- end if
- elseif (right$(tmp$,1) = chr$(72)) or (right$(tmp$,1) = chr$(80)) then
- lastkey$ = tmp$ ' alternate exit keys (up & down)
- tmp$ = chr$(13)
- end if
- end if
-
- '*** now, the non-function key area!
-
- elseif (tmp$ > chr$(31)) and (tmp$ < chr$(127)) then ' good characters?
- if len(strg$) < limit% then ' not too many characters?
- strg$ = left$(strg$,curpos-1) + tmp$ + right$(strg$,len(strg$)-curpos+1)
- if curpos < limit% then
- curpos = curpos + 1 ' don't position the cursor outside the field
- end if
- end if
- elseif tmp$ = chr$(13) then ' carriage return
- lastkey$ = tmp$
- elseif tmp$ = chr$(27) then ' Escape key
- lastkey$ = tmp$
- tmp$ = chr$(13) ' (FORCE THE EXIT)
- elseif tmp$ = chr$(8) then ' backspace/delete
- if curpos > 1 then ' dont do it if you are on the first char.
- if curpos = 2 then
- strg$ = right$(strg$,len(strg$)-1) ' special circum.'s
- elseif curpos = len(strg$)+1 then
- strg$ = left$(strg$,len(strg$)-1) ' more circum.'s
- else
- strg$ = left$(strg$,curpos-2) + right$(strg$,len(strg$)-curpos+1)
- end if
- curpos = curpos-1
- end if
- end if
-
- locate ,startcol
- print strg$; spc(limit% - len( strg$));
- locate ,startcol+curpos-1
- wend
-
- end sub
-