1. Need Advice.
- Posted by Matt Stancliff <sysop at ATL.MINDSPRING.COM> Dec 20, 1996
- 1483 views
I found this little piece of code that came in very useful to me, but I can't get it to take letters. All it does is take number input. Can someone tell me how to get this little thing to take both letters and numbers for input? -Matt INPUT CODE ---------------------------------------------------------------------------- -------------------------------------- function input(sequence text) -- To print a message a return a number sequence inp,cur inp={1,0} puts (1,text) -- message on screen while inp[1] do -- repeat until valid number cur=get_position() -- back to position if not valid inp = get (0) position (cur[1],cur[2]) end while return inp[2] end function ---------------------------------------------------------------------------- --------------------------------------
2. Need Advice.
- Posted by Robert Craig <72614.1667 at COMPUSERVE.COM> Dec 21, 1996
- 1434 views
- Last edited Dec 22, 1996
Matt Stancliff asks: > I found this little piece of code that came in very useful to me, but I > can't get it to take letters. All it does is take number input. > Can someone tell me how to get this little thing to take both letters and > numbers for input? > function input(sequence text) -- To print a message a return a number > sequence inp,cur > inp={1,0} > puts (1,text) -- message on screen > while inp[1] do -- repeat until valid number > cur=get_position() -- back to position if not valid > inp = get (0) > position (cur[1],cur[2]) > end while > return inp[2] > end function As it is, it should accept strings as long as the user of the program types double-quotes around his input, e.g. "my input". A sequence of characters will be returned from the input() function. If you don't want to force the user to use quotes, then you will have to use gets(0) to read the typed input as a string. Then, if the input string contains digit characters you can convert from string form to numeric form, by using value(), or one of the similar routines that Jacques posted a few days ago. -- Rob Craig Rapid Deployment Software