Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Need a special IF statement

TCartledgeTCartledge Posts: 15Member
g'day i have text based menus in my game, after the menu is displayed the program readlns and if a number corresponding with that menu is typed it goes to that selection in the program but if a string is typed is crashes with a runtime error how do i make it if its anything other than number on the menu it goes back to the menu
id like something like this

If Menu is not a Integer then
begin
do this blaa
end;

because i have heaps of menus and doing it like this

IF Menu=1 or Menu-2 etc then
blaa blaa will take way to long

can someone help

Comments

  • ManningManning Posts: 1,621Member
    : g'day i have text based menus in my game, after the menu is displayed the program readlns and if a number corresponding with that menu is typed it goes to that selection in the program but if a string is typed is crashes with a runtime error how do i make it if its anything other than number on the menu it goes back to the menu
    : id like something like this
    :
    : If Menu is not a Integer then
    : begin
    : do this blaa
    : end;
    :
    : because i have heaps of menus and doing it like this
    :
    : IF Menu=1 or Menu-2 etc then
    : blaa blaa will take way to long
    :
    : can someone help

    You can use the Val() function to convert a string to an integer. If the string is not numeric, there is an error condition you can check for. Just look up the function in the help file.
  • TCartledgeTCartledge Posts: 15Member
    : : g'day i have text based menus in my game, after the menu is displayed the program readlns and if a number corresponding with that menu is typed it goes to that selection in the program but if a string is typed is crashes with a runtime error how do i make it if its anything other than number on the menu it goes back to the menu
    : : id like something like this
    : :
    : : If Menu is not a Integer then
    : : begin
    : : do this blaa
    : : end;
    : :
    : : because i have heaps of menus and doing it like this
    : :
    : : IF Menu=1 or Menu-2 etc then
    : : blaa blaa will take way to long
    : :
    : : can someone help
    :
    : You can use the Val() function to convert a string to an integer. If the string is not numeric, there is an error condition you can check for. Just look up the function in the help file.
    :
    how exactly do i use this Val() and i couldn't find anything to do error conditions

  • TCartledgeTCartledge Posts: 15Member
    what i really need to is to tell if an error message will be displayed and stop it from doing that so the program can continue or do something like

    if my menu = a string then
    go back to my menu
    i need some way for the menu to tell if it is a string being input

  • zibadianzibadian Posts: 6,349Member
    : what i really need to is to tell if an error message will be displayed and stop it from doing that so the program can continue or do something like
    :
    : if my menu = a string then
    : go back to my menu
    : i need some way for the menu to tell if it is a string being input
    :
    :
    [code]
    { my menu input into a string}
    Val(MyMenuString, MyMenuInteger, ErrorCode);
    if ErrorCode <> 0 {MyMenuString is not an integer} then
    {Do something if menu is a string}
    else
    {Do something if menu is an integer}
    [/code]
  • TCartledgeTCartledge Posts: 15Member
    : : what i really need to is to tell if an error message will be displayed and stop it from doing that so the program can continue or do something like
    : :
    : : if my menu = a string then
    : : go back to my menu
    : : i need some way for the menu to tell if it is a string being input
    : :
    : :
    : [code]
    : { my menu input into a string}
    : Val(MyMenuString, MyMenuInteger, ErrorCode);
    : if ErrorCode <> 0 {MyMenuString is not an integer} then
    : {Do something if menu is a string}
    : else
    : {Do something if menu is an integer}
    : [/code]
    :
    thanks i will give it a try
  • TCartledgeTCartledge Posts: 15Member
    : : what i really need to is to tell if an error message will be displayed and stop it from doing that so the program can continue or do something like
    : :
    : : if my menu = a string then
    : : go back to my menu
    : : i need some way for the menu to tell if it is a string being input
    : :
    : :
    : [code]
    : { my menu input into a string}
    : Val(MyMenuString, MyMenuInteger, ErrorCode);
    : if ErrorCode <> 0 {MyMenuString is not an integer} then
    : {Do something if menu is a string}
    : else
    : {Do something if menu is an integer}
    : [/code]
    :
    do i have to make MyMenuString
    a variable in the declaration
    such as

    [code]
    var
    MyMenuString : String;
    [/code]
    like that

    i couldn't get it to work here is the code i want it applied to
    [code]
    begin {Main Menu}
    MMenu:= 0;
    MainMenu: {Label}
    ClrScr;
    Game_Heading;
    Writeln;
    MMenu:= 0;
    Main_Menu;
    Readln(MMenu);
    {Menu selection if a value is recieved then menu will redirect}
    Case MMenu of
    1 : Goto NewGame;
    2 : Goto LoadingGame;
    3 : Goto About;
    4 : Goto Help;
    5 : Goto Quit;
    else
    goto MainMenu;
    end;
    end;
    [/code]
    thnx
  • TCartledgeTCartledge Posts: 15Member
    i got it working thanx any way but i still need halp with the file handling post i entered
Sign In or Register to comment.