1. modified prompt_functions

Robert Craig writes:

    "My intention with prompt_number() is to provide beginners with
something easy to use in simple programs. I don't want to complicate it
with lots of extra options and parameters. If it doesn't do exactly
what you want, feel free to copy it, rename it,  and enhance it
to suit your purposes."

Thanks, Robert, as always I appreciated your graciousness and patience
with me.

I am a beginner, as my clutsy efforts to amend prompt_number() clearly
shows.  However, I think it would be best, if at all possible,  to provide a
robust
function which would not have to be re-written or modified by any one,
beginner or novice.

In the case of the function prompt_number() It seems to me that is far less
complicated (for the language user) to have a function that prevents errors
as opposed to returning an error message at some place on the screen which
will have to be erased and then the cursor repositioned for input.
Programming the function to erase the invalid data input and reposition
would not complicate the use of the function for beginners.  It makes the
function very simple to use.

I actually agree with Robert about complicating the function with extra
parameters. However placing the cursor screen position coordinates in the
function seems to kill several birds with one stone -  its more economical
for the programmer by reducing the number of statements and lines,  and less
typing.   Moreover, it allows me to reposition the cursor without using
"get_position()" which would require including "graphics.e".

Anyway, I discovered that my prompt_n() as previously sumbitted to the list
only worked if the prompt started at column 1.  So here is the revised
function.

--
--
------------------------------- prompt.e  -------------------------------
--             (modifications to Euphoria 2.1 prompt functions)
--                              revised 01/22/99
--
--
--  prompt_n(), a modification of prompt_number()
--  syntax:     include get.
--              include prompt.e
--              a = prompt_number(pos,st,s)
--
-- Description: Prompt the user to enter a number.  pos is a sequence of 2
--                      values {line, column} representing the screen
coordinates
--                      ( i.e. position(line, column) ) where the prompt
text  (sequence st)
--                      will be displayed.  The third parameter "s" is a
sequence of
--                      two values {lower, upper} which determine the range
of values
--                      that the user may enter.  If the user enters a
number that is
--                      less than the lower or greater than the upper, or if
the
--                      the user enters a letter instead of a number, the
invalid
--                      input string will be erased and the cursor reset at
the input
--                      position. No error message will be issued.
--
--                      example:  age = prompt_n({4,1},"What is your age? ",
{0,150})
--                      the input prompt, "What is your age?  " is printed
at position(4,1)
--
--


global function prompt_n(sequence pos,sequence prompt, sequence range)
-- Prompt the user to enter a number.
-- A range of allowed values may be specified.
    object answer
    sequence buffer -- holds length of input


    while 1 do

        position(pos[1],pos[2])
         puts(1, prompt)
         buffer = gets(0) -- make sure whole line is read
         answer = value(buffer)

         if answer[1] != GET_SUCCESS or sequence(answer[2]) then

            position(pos[1],pos[2])
            for x = 1 to length(buffer) + length(prompt) do
                puts(1, " ")
            end for

        else
             if length(range) = 2 then
                  if range[1] <= answer[2] and answer[2] <= range[2] then
                          return answer[2]
                  else
                        for x = 1 to length(buffer) + length(prompt) do
                            puts(1, " ")
                        end for
                  end if
              else
                  return answer[2]
              end if
        end if
    end while
end function

--
--
--  prompt_s()   - a modification of prompt_string()
--  syntax:     include get.e
--              include prompt.e
--              a =prompt_s(pos,st)
--  first parameter is a 2 element seqence for line and column coordinates
--  2nd parameter is the prompt string
--  example: answer = prompt_s({4,2}, "Is today your birthday?    ")
--       (prompt text is printed at the 4th line, 2nd column)
--
--
global function prompt_s(sequence pos, sequence prompt)
-- Prompt the user to enter a string

object answer
position(pos[1], pos[2])
puts(1,prompt)
answer = gets(0)
    if sequence(answer) and length(answer)>0 then
return answer[1..length(answer)-1] -- trim the \n
    else
return ""
    end if
end function
--
--

Kenneth  Rhodes
Lyons, GA

new topic     » topic index » view message » categorize

2. Re: modified prompt_functions

Heya, mailing-list people!  Good to see Euphoria's still growing and developing.
 Can't wait to try out the new version...

This is somethin' I wrote to input a string, which can be used as either a
     prompt-style function, or as part of a simple SLE.  I suppose it could be
     modified to guarantee a valid numerical entry, but I haven't done that yet. 
     Works only in text modes.
Handles the following keys:
ESC, Backspace, Enter, Left and Right Arrow, Insert, Delete, Home, and End.
Can be placed at specific coordinates.
Can be limited in visual size.  (You're screen may be 80 characters wide, but
you only want the input field to be 40 characters wide.)
Can be limited in input size (or unlimited).
Can be masked with the character of your choice for passwords.
If the text length is > the visible length, uses horizontal scrolling so as to
stay within the visible boundaries.

Could probably use some tweakin', but I smashed all the bugs I've noticed...

Okay, it uses another include of mine...I'll upload it to the web and post a
link to save e-mail space.

http://members.aol.com/falkon1313/programming/inptstr.zip  (6029 bytes)

Hope somebody gets some use out of that.
Falkon

new topic     » goto parent     » topic index » view message » categorize

3. Re: modified prompt_functions

----- Original Message -----
From: Falkon1313 <falkon1313 at AOL.COM>
To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Thursday, January 28, 1999 1:21 AM
Subject: Re: modified prompt_functions


>Heya, mailing-list people!  Good to see Euphoria's still growing and
developing.  Can't wait to try out the new version...
>
>     This is somethin' I wrote to input a string, which can be used as
either a prompt-style function, or as part of a simple SLE.  I suppose it
could be modified to guarantee a valid numerical entry, but I haven't done
that yet.  Works only in text modes.
>Handles the following keys:
>ESC, Backspace, Enter, Left and Right Arrow, Insert, Delete, Home, and End.
>Can be placed at specific coordinates.
>Can be limited in visual size.  (You're screen may be 80 characters wide,
but you only want the input field to be 40 characters wide.)
>Can be limited in input size (or unlimited).
>Can be masked with the character of your choice for passwords.
>If the text length is > the visible length, uses horizontal scrolling so as
to stay within the visible boundaries.
>
>Could probably use some tweakin', but I smashed all the bugs I've
noticed...
>
>Okay, it uses another include of mine...I'll upload it to the web and post
a link to save e-mail space.
>
>http://members.aol.com/falkon1313/programming/inptstr.zip  (6029 bytes)
>
>Hope somebody gets some use out of that.
>Falkon
>

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu