
-----------------------------------
vdemons
Sun May 01, 2011 3:59 pm

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.

-----------------------------------
Insectoid
Sun May 01, 2011 4:20 pm

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.

-----------------------------------
HRI
Sat May 14, 2011 7:07 pm

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.

setscreen ("graphics:max;max,offscreenonly") % max size and simply put, no flickering
var ch : string (1) := "" % holds entered character
var input : flexible array 1..0 of string (1) % dynamic array of characters
var entry : string
int delay

loop
    if hasch % if key was pressed
    then
        getch (ch) % read key into variable ch
    
        exit when ch = KEY_ENTER % exit if enter key

        if ch = KEY_BACKSPACE and upper (input) > 0 % if backspace pressed and there's a character to delete 
        then
            new input, upper (input) - 1 % decrease array size (last character is erased)
            put "\b" .. % put a backspace
        elsif ord (ch) >= ord ('0') and ord (ch) 