Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Limiting input
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
noobsauce




PostPosted: 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.
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: 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.
noobsauce




PostPosted: 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?
Tony




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Insectoid




PostPosted: 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.
noobsauce




PostPosted: 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?
Insectoid




PostPosted: 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.
Clayton




PostPosted: 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.
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: 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.
noobsauce




PostPosted: Thu Oct 09, 2008 8:36 pm   Post subject: Re: Limiting input

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




PostPosted: 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
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 11 Posts ]
Jump to:   


Style:  
Search: