Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4095
Number of posts: 14007

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Need a special IF statement Posted by TCartledge on 2 Sept 2003 at 7:08 PM
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
Report
Re: Need a special IF statement Posted by Manning on 2 Sept 2003 at 7:22 PM
: 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.
Report
Re: Need a special IF statement Posted by TCartledge on 2 Sept 2003 at 7:28 PM
: : 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

Report
Re: Need a special IF statement Posted by TCartledge on 3 Sept 2003 at 12:24 AM
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

Report
Re: Need a special IF statement Posted by zibadian on 3 Sept 2003 at 12:49 AM
: 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
:
:
{ 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}

Report
Re: Need a special IF statement Posted by TCartledge on 3 Sept 2003 at 5:28 PM
: : 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
: :
: :
:
: { 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}
: 

:
thanks i will give it a try
Report
Re: Need a special IF statement Posted by TCartledge on 3 Sept 2003 at 6:42 PM
: : 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
: :
: :
:
: { 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}
: 

:
do i have to make MyMenuString
a variable in the declaration
such as

var
MyMenuString : String;

like that

i couldn't get it to work here is the code i want it applied to
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; 

thnx
Report
Re: Need a special IF statement Posted by TCartledge on 4 Sept 2003 at 12:12 AM
i got it working thanx any way but i still need halp with the file handling post i entered



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.