Computer Science Canada

Limiting input

Author:  noobsauce [ 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.

Author:  [Gandalf] [ 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.

Author:  noobsauce [ 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?

Author:  Tony [ 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.

Author:  Insectoid [ 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.

Author:  noobsauce [ 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?

Author:  Insectoid [ 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.

Author:  Clayton [ 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.

Author:  Insectoid [ 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.

Author:  noobsauce [ Thu Oct 09, 2008 8:36 pm ]
Post subject:  Re: Limiting input

nvm, i figured out how to do it. Thanks guys

Author:  rto [ 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


: