Page 1 of 1 1
Topic Options
#24504 - 2002-07-06 03:35 PM Limiting string input
zenart Offline
Lurker

Registered: 2002-06-13
Posts: 4
Loc: melb
Hi
I have a simple question,

I am writting a script where I ask the user to
input a three digit string.

AT (5,10) " Enter the three Digit Machine ID "
AT (6,10) " (eg 601) : " Gets $IMAGE

How do I limit the input to only three digits and how to I stop spaces from being inputed as part of the string.

???

Top
#24505 - 2002-07-06 03:42 PM Re: Limiting string input
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Well,

you can check for the length of the string and if there are spaces included :

code:
break on


:again
AT (5,10) " Enter the three Digit Machine ID "
AT (6,10) " (eg 601) : " Gets $IMAGE

if len($image) > 3 or instr($image," ")
cls beep goto again
endif


get $

_________________________



Top
#24506 - 2002-07-06 03:47 PM Re: Limiting string input
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
I like Jochens idea, but here's the other way of doing it ...you decide:

break on

? "Enter the three Digit Machine ID (eg 601): "

$done = 0
$ans = ""

do
 get $c
 if asc($c) = 3 ; ^c break ?
  $done = 1
 else
  if $c <> " "
   $c = ucase($c)
   $c ; echo
   $ans = $ans + $c
  else
   beep
  endif
 endif
until $done or len($ans) = 3

exit 1


-Shawn

Top
#24507 - 2002-07-06 03:56 PM Re: Limiting string input
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Neat !
_________________________



Top
#24508 - 2002-07-06 03:59 PM Re: Limiting string input
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Yeah, but one can't backspace with this routine ... maybe should fix ? I would still recommend, like you, just use the GETS() in a LOOP, and check for good string ...
Top
#24509 - 2002-07-06 04:02 PM Re: Limiting string input
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
We had that once I think with Bryce's password char input loop ?

Loads of code though ...

J.
_________________________



Top
#24510 - 2002-07-08 01:26 PM Re: Limiting string input
zenart Offline
Lurker

Registered: 2002-06-13
Posts: 4
Loc: melb
YE thank for that I like jpols suggestion,

But what about a carriage return. How would i filter that out

Top
#24511 - 2002-07-08 01:29 PM Re: Limiting string input
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
change the line:
if len($image) > 3 or instr($image," ")
to:
if len($image) <> 3 or instr($image," ")

thanks jochen.

[ 08 July 2002, 13:33: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#24512 - 2002-07-08 01:30 PM Re: Limiting string input
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
A 'carriage return' ie. ENTER completes the string input , so it is not passed by default

hth
J.
_________________________



Top
#24513 - 2002-07-09 11:43 AM Re: Limiting string input
zenart Offline
Lurker

Registered: 2002-06-13
Posts: 4
Loc: melb
The example below works well
thanks for all your help.

if len($image) <> 3 or instr($image," ")

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 293 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.059 seconds in which 0.024 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org