Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Grumpfish Library 3.2 - <b>up_n_down()</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
UP_N_DOWN()

    This little function allows for flexible upper and lower case data
    entry.  Although it is not necessarily proper database design to
    have one field for the entire name (first and last), a lot of people
    do it anyway. If you are one of these people, and you would like
    your users to be able to enter proper names (upper and lower),
    UP_N_DOWN() is for you.

    Syntax

    ...PICTURE UP_N_DOWN(@<string>)

    Required Parameter

    <string> is the character string that you are GETting, and this must
    be passed by reference (i.e., prefaced by an at ("@") sign).

    Return Value

    UP_N_DOWN()'s return value is a character string of exactly the same
    length as the variable, consisting entirely of the letter
    "X".  This is in accordance with the inherent requirement of the
    PICTURE clause, although it is a moot point because the variable
    will already have been altered within UP_N_DOWN().

    Notes

    UP_N_DOWN() simulates an actual GET by trapping each keystroke and
    acting accordingly.  It is designed for use with character
    variables, and you must pass the variable by reference (i.e.,
    preceded by "@"). This is necessary so that the value of the
    variable can be manipulated directly within the function.

    As written, control will remain within UP_N_DOWN() until one of the
    following traditional GET navigation keys is pressed: Enter, Esc,
    Ctrl-W, UpArrow, DownArrow, PgUp, and PgDn.  If you want to modify
    this logic, simply modify the DO WHILE statement to suit your needs.
    The source code is contained in $UPNDOWN.PRG.

    The critical variable is NEXTUPPER.  The value of this variable
    determines whether or not the next character is to be upper-case.
    Upon entering UP_N_DOWN(), we assume that the first character is to
    be upper-case, and thus set NEXTUPPER to True (.T.).  There are
    three courses of action dependent upon the key pressed:

    - Alpha characters (ASCII values between 65 and 90 or 97 and
      122): added to the variable.  If NEXTUPPER is True, they are
      converted to upper-case.  After adding the character,
      NEXTUPPER is set to False.

      But suppose that you wanted to enter the word "dBASE". Because the
      letter "d" falls at the beginning of the word, it will be
      converted to upper case.  Or will it?  Fortunately, you can
      override this forced upper case conversion.  Simply hold down the
      Shift key while typing the first letter of a word, and it will be
      entered as lower-case. It is easy enough to test for whether the
      keypress was an upper-case letter (because it would be between 65
      and 90).  If it is, and NEXTUPPER is True, we then add 32 to the
      ASCII value of the keypress to force it to lower case.

    - Space Bar - adds a trailing space to the variable and sets
      NEXTUPPER to True in preparation for the beginning of the next
      word.

    - Backspace - removes the last character from the variable. We use
      the Clipper SCROLL() command to "erase" the last character (this
      is faster and much simpler than redisplaying the entire string).
      We then shake the dust out of our eyes from all that excitement
      and see where we are in the string.  If we are all the way back at
      the beginning of the string, or resting upon a space (ASCII 32),
      NEXTUPPER is set back to True.

    When one of the aforementioned keys is pressed to fall out of the DO
    WHILE loop, it is stuffed back into the keyboard buffer so that it
    can be processed.  The string is then padded back to its original
    length, and color is reset to its previous setting.

    UP_N_DOWN() is a very open-ended function.  For example, you could
    add more smarts to detect occurrences of "Mac    "Mc    or "O'    which
    all begin common mixed case surnames.

    Caveat

    As with CALC_PIC(), UP_N_DOWN() can only be used with one GET and
    one READ.  If you are GETting multiple variables on the same READ,
    and one of those variables uses UP_N_DOWN() as the PICTURE clause,
    the cursor will jump to that variable no matter where it is in
    the list. This is unavoidable because, unlike a VALID clause
    which is processed only after passing through the corresponding GET,
    all PICTURE clauses are processed before control is passed to the
    READ statement.

    Sample Usage

    mstring = SPACE(20)                             
    @ 10, 10 GET mstring PICTURE UP_N_DOWN(@mstring)
    READ                                            

See Also: CALC_PIC()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson