1. modified prompt functions
- Posted by Kenneth Rhodes <krhodes at CYBERSOUTH.COM> Jan 21, 1999
- 415 views
- Last edited Jan 22, 1999
Hello all The error message and "new line" features of Euphoria 2.1's prompt functions annoyed me. I wanted the cursor to relocate at the input position upon error, with no error message. It seemed to me that if the function effectively prevents you from making an invalid data entry, then the error message is just in the way. So, I reviewed all the input/prompt functions I could find from the list and tinkered with Rob's functions. I have also added a line, column positioning paramenter to these functions. Anyway, I thought I'd post them in case any of you guys are interested. Ken Rhodes -- ------------------------------- prompt.e ------------------------------- -- (modifications to Euphoria 2.1 prompt functions) -- -- -- -- 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}) -- 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) position(pos[1],pos[2]) if answer[1] != GET_SUCCESS or sequence(answer[2]) then position(pos[1],length(prompt)) for x = 1 to length(buffer) do puts(1, " ") end for position(pos[1],pos[2]) else if length(range) = 2 then if range[1] <= answer[2] and answer[2] <= range[2] then return answer[2] else position(pos[1],length(prompt)) for x = 1 to length(buffer) do puts(1, " ") end for position(pos[1],pos[2])-- leave this alone! end if else return answer[2] end if end if end while end function -- -- -- prompt_s() - a minor 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
2. Re: modified prompt functions
- Posted by Irv Mullins <irv at ELLIJAY.COM> Jan 21, 1999
- 415 views
- Last edited Jan 22, 1999
On Thu, 21 Jan 1999 21:49:06 -0500, Kenneth Rhodes <krhodes at CYBERSOUTH.COM> wrote: >Hello all > >The error message and "new line" features of Euphoria 2.1's prompt >functions annoyed me. I wanted the cursor to relocate at the input position >upon error, with no error message. It seemed to me that if the function >effectively prevents you from making an invalid data entry, then the error >message is just in the way. So, I reviewed all the input/prompt functions >I could find from the list and tinkered with Rob's functions. > >I have also added a line, column positioning paramenter to these functions. >Anyway, I thought I'd post them in case any of you guys are interested. > Thanks, The other annoying thing about prompt_number() is this: atom x x = prompt_number("Enter a number between 4.5 and 6.7",{4.5,6.7}) and make a mistake! Irv
3. Re: modified prompt functions
- Posted by Robert Craig <rds at EMAIL.MSN.COM> Jan 21, 1999
- 428 views
- Last edited Jan 22, 1999
Irv Mullins writes: > The other annoying thing about prompt_number() is this: > atom x > x = prompt_number("Enter a number between 4.5 and 6.7",{4.5,6.7}) > and make a mistake! Whoops! Thanks for pointing that out. I'll change the printf statement in prompt_number() to use %g format instead of %d: printf(1, "A number from %g to %g is expected here - try again\n", range) That seems to do the job. Kenneth Rhodes writes: > The error message and "new line" features of > Euphoria 2.1's prompt functions annoyed me. 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. I was getting a lot of feedback that beginners didn't know how to input a number. get(0) has complications that tend to confuse people. Regards, Rob Craig Rapid Deployment Software http://members.aol.com/FilesEu/
4. Re: modified prompt functions
- Posted by LEVIATHAN LEVIATHAN <kiduv1999 at HOTMAIL.COM> Jan 23, 1999
- 411 views
Humm... Okay, I'm having problems with prompt_string() and program switching (which two programs are in separate procedures), in which I keep getting undefined errors from it. What i'm doing witrh it, is taking Rob's Celcius program, and a sloghtly modified farenhei.ex program, putting them in the same program, with separate procedures, and the main procedure doing the switching. I keep getting errors like this: tempconv.ex:33 in procedure main() true/false condition must be an ATOM ... called from tempconv.ex:41 --> see ex.err tempconv.ex:33 in procedure main() true/false condition must be an ATOM ... called from tempconv.ex:41 Global & Local Variables c:\EUPHORIA\INCLUDE\get.e: input_file = <no value> input_string = <no value> string_next = <no value> ch = <no value> tempconv.ex: ftemp = <no value> ctemp = <no value> f_or_c = {99'c'} Uhm, what's going on here? I don't get it... :) TIA, -- "LEVIATHAN" ______________________________________________________ Get Your Private, Free Email at http://www.hotmail.com
5. Re: modified prompt functions
- Posted by Lucius Hilley III <lhilley at CDC.NET> Jan 23, 1999
- 425 views
The answer is simple. You are doing something like. if function() then commands end if function() is returning a sequence for a value. if statements require the end value to be an ATOM. Sincerely, Lucius L. Hilley III On Sat, 23 Jan 1999 12:05:39 PST, LEVIATHAN LEVIATHAN <kiduv1999 at HOTMAIL.COM> wrote: >Humm... > >Okay, I'm having problems with prompt_string() and program switching >(which two programs are in separate procedures), in which I keep getting >undefined errors from it. > >What i'm doing witrh it, is taking Rob's Celcius program, and a sloghtly >modified farenhei.ex program, putting them in the same program, with >separate procedures, and the main procedure doing the switching. I keep >getting errors like this: > >tempconv.ex:33 in procedure main() >true/false condition must be an ATOM >... called from tempconv.ex:41 >--> see ex.err > >tempconv.ex:33 in procedure main() >true/false condition must be an ATOM > >... called from tempconv.ex:41 > >Global & Local Variables > > c:\EUPHORIA\INCLUDE\get.e: > input_file = <no value> > input_string = <no value> > string_next = <no value> > ch = <no value> > > tempconv.ex: > ftemp = <no value> > ctemp = <no value> > f_or_c = {99'c'} > >Uhm, what's going on here? I don't get it... :) > >TIA, > >-- "LEVIATHAN" > > >______________________________________________________ >Get Your Private, Free Email at http://www.hotmail.com