Author |
Message |
noobsauce
|
Posted: Thu Oct 09, 2008 5:56 pm Post subject: Limiting input |
|
|
How do i limit the input to for example 3 characters without like doing a string and ignoring everything after the 3rd part. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
[Gandalf]
![](http://compsci.ca/v3/uploads/user_avatars/189297994e4c716fec7f1.png)
|
Posted: Thu Oct 09, 2008 6:06 pm Post subject: RE:Limiting input |
|
|
Not sure exactly what you're looking for, but a loop with getch() or Input.KeyDown() would work. |
|
|
|
|
![](images/spacer.gif) |
noobsauce
|
Posted: Thu Oct 09, 2008 6:20 pm Post subject: Re: Limiting input |
|
|
What i am asking is that if for example, i ask for someone's student number.
I know it is 9 digits, how do I prevent the user from entering over 9 digits? |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Thu Oct 09, 2008 6:24 pm Post subject: RE:Limiting input |
|
|
you ask for the input 1 character at a time (using getch()) and keep a count of how much the user has entered so far. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Thu Oct 09, 2008 6:25 pm Post subject: RE:Limiting input |
|
|
Use getch () in a for loop, and add the input to a string. This way, you can getch 9 times, and it will automatically end the getting. |
|
|
|
|
![](images/spacer.gif) |
noobsauce
|
Posted: Thu Oct 09, 2008 8:03 pm Post subject: Re: Limiting input |
|
|
Thanks for the reply guys, I really appreciate it.
I have another problem
I need the user to input a name, first and last, but the get statement only gets the info until the space, so the last name is ignored, how do I get the full name in 1 string? |
|
|
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Thu Oct 09, 2008 8:09 pm Post subject: RE:Limiting input |
|
|
when typing multiple words into a string, you need to put quoteations around them.
input (Harold Haselhoff) will return 'Harold', while input ("Harold Haselhoff") will return Harold Haselhoff. |
|
|
|
|
![](images/spacer.gif) |
Clayton
![](http://compsci.ca/v3/uploads/user_avatars/1718239683472e5c8d7e617.jpg)
|
Posted: Thu Oct 09, 2008 8:16 pm Post subject: RE:Limiting input |
|
|
Actually, not quite. get only captures input up to the first whitespace in the string that it's trying to capture from. To counter this, you'll need to use:
Turing: | var foo : string := "";
get foo :*;
|
the :* following the get statement will make sure that you capture all input that the user provides, even whitespce. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Thu Oct 09, 2008 8:23 pm Post subject: RE:Limiting input |
|
|
I've always used quotations, but then, I never knew you could do it your way. Oh, well, Turing is behind me.
But quotations will cancel out the 'no white space' thing. |
|
|
|
|
![](images/spacer.gif) |
noobsauce
|
Posted: Thu Oct 09, 2008 8:36 pm Post subject: Re: Limiting input |
|
|
nvm, i figured out how to do it. Thanks guys |
|
|
|
|
![](images/spacer.gif) |
rto
|
Posted: Fri Oct 10, 2008 8:12 am Post subject: RE:Limiting input |
|
|
For reference, you could also make a second variable. might take a bit of extra time but no extra steps are needed in the inputting stage |
|
|
|
|
![](images/spacer.gif) |
|