[SOLVED] Preventing incorrect user inputs. lazarus / 61-Beginners ---------------------------------------------------------------------- hymcode · 2021-01-08 11:30 Hello everyone, I'm currently trying to make my own TUI menu, and I'm having issues when a user inputs a value that isn't a number. I've listed my code below for reference: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  choice : Integer; procedure error;begin  writeln('Incorrect Input. Please try again...');end;  begin  repeat    1: clrscr;    writeln('My Menu');  gotoxy(4, 3);    writeln('1. Option 1');    gotoxy(4, 4);    writeln('2. Option 2');    gotoxy(4, 5);    writeln('3. Exit Program');    writeln;    write('Please select an option: ');    readln(choice);     case choice of      1: optionOne;      2: optionTwo;      3: quit;    end;     if (choice < 1) or (choice > 3) then    begin      error;      readln;    end;  until choice = 3;end.                    The issue I am having is that if a user inputs a or A for example the program will crash because it can't convert the character into a number, which makes sense to me, but I'm having a code blank moment on the best way to resolve this. In addition to this my other dilemma is that I would like to get it working on an OpenVMS system which uses HP Pascal and can use slightly different syntax in comparison to Free Pascal, like for Try Except statements are not supported in HP Pascal if I remember correctly.  Any help would be greatly appreciated. Solution [Pascal] Thank you to everyone with their advice and input. I was able to achieve my needs using the method below: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  choice, error_stat : Integer;  choiceStr : String; procedure error;begin  writeln('Incorrect Input. Please try again...');end;  begin  choice := 0;  choiceStr := '';  error_stat := 0;   repeat    1: clrscr;    writeln('My Menu');    gotoxy(4, 3);    writeln('1. Option 1');    gotoxy(4, 4);    writeln('2. Option 2');    gotoxy(4, 5);    writeln('3. Exit Program');    writeln;    write('Please select an option: ');    readln(choiceStr);     {$I-}    ReadStr(choiceStr, choice);    {$I+}    error_stat := IOResult;     case choice of      1: optionOne;      2: optionTwo;      3: quit;    end;     if (choice < 1) or (choice > 3) then    begin      error;      readln;    end;  until choice = 3;end. Solution [HP PASCAL] Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  procedure error;begin  writeln('Incorrect Input. Please try again...');end;  begin  repeat    choice := 0;    choiceStr := '';    writeln('My Menu');    writeln('1. Option 1');    writeln('2. Option 2');    writeln('2. Exit Program');    writeln;    write('Please select an option: ');    readln(choiceStr);    readv(choiceStr, choice, error := continue);     case choice of      1: optionOne;      2: optionTwo;    3: quit;    end;     if (choice < 1) or (choice > 3) then    begin    error;      writeln;    end;  until choice = 3; ---------------------------------------------------------------------- PascalDragon · 2021-01-08 12:13 Quote from: hymcode on January 08, 2021, 12:30:43 pmAny help would be greatly appreciated. You need to tell the compiler that you want to handle I/O errors yourself for the Readln: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     write('Please select an option: ');    {$push}    {$I-}    readln(choice);    {$pop}    if IOResult <> 0 then      choice := 0;  For more information see here. ---------------------------------------------------------------------- lucamar · 2021-01-08 12:15 Or you could just use a char as Choice: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     var    choice : Char;         procedure error;    begin      writeln('Incorrect Input. Please try again...');    end;         begin      repeat        clrscr;        writeln('My Menu');        gotoxy(4, 3);        writeln('1. Option 1');        gotoxy(4, 4);      writeln('2. Option 2');        gotoxy(4, 5);        writeln('3. Exit Program');        writeln;        write('Please select an option: ');        read(choice);             case choice of          '1': optionOne;          '2': optionTwo;          '3': quit;          else begin              error;              readln;            end;        end;           until choice = '3';    end. ---------------------------------------------------------------------- PascalDragon · 2021-01-08 12:21 Quote from: lucamar on January 08, 2021, 01:15:17 pmOr you could just use a char as Choice: You should keep the Readln instead of using Read however as otherwise there'll still be a linefeed/carriage return in the buffer the next time you read from Standard Input which might mess up things. ---------------------------------------------------------------------- Handoko · 2021-01-08 13:20 @hymcode Maybe you can try this fully working short demo: https://forum.lazarus.freepascal.org/index.php/topic,43045.msg307111.h tml#msg307111 ---------------------------------------------------------------------- Bart · 2021-01-08 13:44 Use something like: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ...  repeat    Ch := UpCase(ReadKey); //ReadKey function in in unit Crt  until (Ch in ['1','2','3']);...Use can press any key they want, but your program only continues until he presses '1', '2', or '3'; Bart