Computer Science Canada How to prevent user input error! |
Author: | vdemons [ Sun May 01, 2011 3:59 pm ] |
Post subject: | How to prevent user input error! |
i would like to know how to prevent user input error, for example; var inputdelay:int put "Please enter your disired time delay: ".. get inputdelay if i initialize it to int and someone enters a string turing will automatically stop the program and pop the code window backup. my question it if you can prevent that and output an error message and repeat the user input statement. |
Author: | Insectoid [ Sun May 01, 2011 4:20 pm ] |
Post subject: | RE:How to prevent user input error! |
You'll need 2 variables. A string, and an int. get the string, then use strintok() and strint() to convert it to an integer and store it in your integer variable. |
Author: | HRI [ Sat May 14, 2011 7:07 pm ] | ||||||
Post subject: | Re: How to prevent user input error! | ||||||
Here's a piece of code that will get a string one character at a time, check to see whether it's a number, and then add it if it is. It's easy to set a length too.
The reason I do it this way is because I simply don't know of a way to accomplish
Please give me a shout if you do :3 Alternatively, basically the last post put into code
I like the first way better because it doesn't allow other characters than numbers period, but the second works too. |