1. Re: Number Input--oops

Craig Gilbert wrote:
>=20
> ---------------------- Information from the mail header ---------------=
--------
> Sender:       Euphoria Programming for MS-DOS <EUPHORIA at MIAMIU.ACS.MUOH=
IO.EDU>
> Poster:       Craig Gilbert <cgilbert at CENNET.MC.PEACHNET.EDU>
> Subject:      Number Input--oops
> -----------------------------------------------------------------------=
--------
>=20
> >>>Bryan wrote:  . . .how do I let the player enter numbers (such
> >>>as a bet), and have the variable equal the number entered and
> >>>not the ASCII number?  . . .<skipped> . . . They enter "15",
> >>>but the sequence variable is set to {49,53} . . .
>=20
> >>Craig wrote: <bad advice skipped >
>=20
> >Ad Rienks wrote:
> >Bryan,
> >
> >Maybe you can use the input function, written by 'unknown coder'
> >(actually a corporate attempt of some coders). This function can
> >also be found on the ftp site of Irv Mullins (that's his name, I think=
)
> >
> > <code skipped>
> >--Using the function get(0) in this routine you don't need value() . .=
 .
>=20
>      Ad Rienks is absolutely right.  Using get(0) is much more
> straightforward than first getting a string and then converting it with
> value(), whether you use the 'unknown coder' input() or not.
>      Sorry about the bum steer . . .
>=20
> Craig

It=B4s been a while since I have written to the Euphoria list but I do
read all the messages. Suprised to see the input() that formed part of a
program I sent in months ago beeing passed. It has been modified in a
couple of places - for the better. Just in case there is anyone
interesed I have inclosed 3 input routines I generally use.
The input_limit() is handy for controlling input from a user.

-- cut here
include get.e
include graphics.e
global function input_num(sequence text) -- To print a message & return
a number
sequence inp,cur
inp=3D{1,0}
    puts (1,text)                   -- message on screen
    while inp[1] do                 -- repeat until valid number
    cur=3Dget_position()              -- get current cursor position
    inp =3D get (0)
    position (cur[1],cur[2])        -- back to position if not valid
    end while
   =20
    return inp[2]    =20
end function

---------------------------- input_text-------------------------------
global function input_text(sequence text) -- To print a message and
return=20
sequence txt                              -- text from user
    puts (1,text)                         -- message on screen
    txt=3D gets (0)                       =20
    return txt    =20
end function

--input accepting only values in limit
--usage example: n=3Dinput_limit("Number from 3 to 8 but not
5",{3,4,6,7,8})

global function input_limit(sequence text,sequence limit)
integer search
sequence inp,cur
inp=3D{1,0}
    puts (1,text)                   -- message on screen
    while inp[1] do                 -- repeat until valid number
    cur=3Dget_position()              -- back to position if not valid
    inp =3D get(0)
    search=3Dfind(inp[2],limit)
    if search=3D0 then inp=3D{1,0}  end if
    position (cur[1],cur[2])
    end while
   =20
    return inp[2]    =20
end function
--cut here

Saludos=20
Adam H. Jackson 'Unknown coder'

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu