Help on Inputting Menus 
Author Message
 Help on Inputting Menus

I am creating a very small program.

Need info on a problem:

WriteLn ('Input your choice <A/B> :');
ReadLn It;
If It = 'A' Then
        blah
        blah*
        blah
Else
        blah
        blah

...and so on..

The A choice works fine, yet when I choose the B choice, it starts up at the
2nd line under the A choice stuff.. (it starts where the * is)

Any info? Any new ways I can do this? Hurry! I need this program in
tomorrow, yet still after that would like to know how to get this running
right..

Thanks.

- James Kennemore -
 - Greenwood,  SC -



Thu, 16 Jul 1998 03:00:00 GMT  
 Help on Inputting Menus
-----BEGIN PGP SIGNED MESSAGE-----


Quote:
>WriteLn ('Input your choice <A/B> :');
>ReadLn It;
>If It = 'A' Then
>        blah
>        blah*
>        blah
>Else
>        blah
>        blah

>...and so on..

>The A choice works fine, yet when I choose the B choice,
>it starts up at the 2nd line under the A choice stuff..
>(it starts where the * is)

>Any info? Any new ways I can do this? Hurry! I need this
>program in tomorrow, yet still after that would like to
>know how to get this running right..

Pascal works like this: If A then B else C.  A, B, and C all
have to be a single statement.  Obviously, that could be very
limiting; hence, the keywords "begin" and "end" are used
to separate off chunks that are interpreted as a single
statement.

Try:

Write ('Input your choice A/B');
Readln It;
If A then
   begin
        DoA (1);
        DoA (2);
        Writeln ('A')
   end
   else
   begin
        DoB (1);
        DoB (2);
        Writeln ('B')
   end;

Note that the last statement before the end keywords lack
a semicolon, as does the word 'end'.  Semicolons are usually
interpreted as being the end of a statement.  Note, however,
that DoA(2) IS followed by a semicolon.  (Why?)

Quote:
>Thanks.

You're welcome.

dave

-----BEGIN PGP SIGNATURE-----
Version: 2.6.2

iQEVAwUBMQvz4jVTwUKWHSsJAQEm6Af/SKj5Wqy6DH8+DmZliLICYeaKB84nZjDW
gWPB1bTOphV7sw86qZYAtIfy/UWcWNJCpsO/wNkgYhJilTrSafv/1174nSJAJOto
WOfpheKMB9VLQXmqPxlVzpHw3eKH3CHj5QrYLeLi6UaKgAIDkrF3KZjKwG4B7DBd
mfMxbY+EYcszr8/oWaE6L42/YDVOhgPhtqXdWTsUrvvez3/ZDqflRbPc4wZ84C13
RGz3pphBCxsooKkZENn/H6cbpP3IRA38GVZpd/6yjqjIHjgAnfPk17titeE4PxNv
P7OtDt+yenAduFW4nRGnflKOha9COXT486+Ci0XJ/gICJhyf2TOegw==
=NXv8
-----END PGP SIGNATURE-----
---
David E. Smith, c/o Southeast Missouri State University
1210 Towers South, Cape Girardeau MO USA 63701-4745

Do not use old PGP keys 0x92732139 and 0xFF829C15.
http://www.midwest.net/scribers/dsmith/



Thu, 16 Jul 1998 03:00:00 GMT  
 Help on Inputting Menus

Quote:

>WriteLn ('Input your choice <A/B> :');
>ReadLn It;
>If It = 'A' Then
>        blah
>        blah*
>        blah
>Else
>        blah
>        blah

>...and so on..

You're short of a BEGIN and END, i.e,
        IF it = 'A' THEN BEGIN
          blah;
          blah;
          blah;
        END
        ELSE BEGIN
          blah;
          blah;
          blah;
        END;

If you have more than one statement following the flow-control
statement (REPEAT, WHILE, IF,...) then you have to use a BEGIN - END
pair.  If you've a lot of choices, maybe you want to look at
using a CASE statement.

For me (ducking to avoid the flames) this is one of the most annoying
things about Pascal, these un-necessary BEGINS and the fickle positioning
of semi-colons.  Modula-2 cleared up the problem quite nicely...

ChrisR:



Fri, 17 Jul 1998 03:00:00 GMT  
 Help on Inputting Menus
On Sun, 28 Jan 1996 21:13:47 GMT, James Kennemore

Quote:

>WriteLn ('Input your choice <A/B> :');
>ReadLn It;
>If It = 'A' Then
>        blah
>        blah*
>        blah
>Else
>        blah
>        blah

>The A choice works fine, yet when I choose the B choice, it starts up at the
>2nd line under the A choice stuff.. (it starts where the * is)

<chuckle> You forgot a "begin" block.  Remember, any single statement in
Pascal may be replaced by a block of code delimited with "begin" and
"end".

The code you wrote would be interpreted something like this:

if lt='A' then
   blah;
blah;
blah;

Rewrite your code as

Readln(lt);
if lt='A' then
begin
   blah;
   blah;
   blah
end else
begin
   yadda;
   yadda;
   yadda
end;

--

"Be wary of strong spirits.  It can make you shoot at tax collectors...
and miss." --RAH



Fri, 17 Jul 1998 03:00:00 GMT  
 Help on Inputting Menus

Quote:

> WriteLn ('Input your choice <A/B> :');
> ReadLn It;
> If It = 'A' Then
>         blah
>         blah*
>         blah
> Else
>         blah
>         blah

> ...and so on..

> The A choice works fine, yet when I choose the B choice, it starts up at the
> 2nd line under the A choice stuff.. (it starts where the * is)

> Any info? Any new ways I can do this? Hurry! I need this program in
> tomorrow, yet still after that would like to know how to get this running
> right..

This is as it should be.  If you want the ELSE to be related to the IF then you
need to do something like this:
 If It = 'A' Then
        BEGIN
         blah
         blah*
         blah
        END
 Else
        BEGIN
         blah
         blah
        END;
(note:position of ; is important on ENDS}

Actually, I am supprised that the code - as shown - even compiled.  It should
have complained the ELSE is not a valid statement (unless , of course, you have
one of those compilers that doesn't check such stuff)

Good Luck

Paul J.



Fri, 17 Jul 1998 03:00:00 GMT  
 Help on Inputting Menus

Quote:


>Subject: Help on Inputting Menus
>Date: Sun, 28 Jan 1996 21:13:47 GMT
>I am creating a very small program.
>Need info on a problem:
>WriteLn ('Input your choice <A/B> :');
>ReadLn It;
>If It = 'A' Then
>        blah
>        blah*
>        blah
>Else
>        blah
>        blah
>...and so on..
>The A choice works fine, yet when I choose the B choice, it starts up at the
>2nd line under the A choice stuff.. (it starts where the * is)
>Any info? Any new ways I can do this? Hurry! I need this program in
>tomorrow, yet still after that would like to know how to get this running
>right..
>Thanks.
>- James Kennemore -
> - Greenwood,  SC -

Do it like this...

If It = 'A' Then
        begin
                blah
                blah*
                blah
        end
Else
        begin
                blah
                blah
        end;

...and so on..



Sun, 19 Jul 1998 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Thanks for Help on Inputting Menus

2. Help: Can't create Pop Menu

3. Menu System Help

4. menu help

5. Help needed re: Menu Procedure

6. Help please with right-click menu on TDBEdit

7. wmfh10.zip TP units for windows, menus, help, etc

8. Please help MENU SYSTEM

9. need help with programmatic assignment of Popup menu using TTreeView component

10. HELP !!!! Pascal OOPS - Menu Question

11. HELP !!!! Pascal OOPS - Menu Question

12. HELP ON MAKING MENU

 

 
Powered by phpBB® Forum Software