Board index » delphi » Can someone help?

Can someone help?

Could anyone tell me what I'm doing wrong with the following procedure?

I get a ';' expected error when I try to run the program and it points to
the first occurrence of isvalid -'true'

I can get this rather simple routine to work fine under VB but I'm just
learning Pascal so any help would be highly appreciated.

thanks

Procedure Calculate_Customer_Status (VAR business,customer: real; VAR
History,answer,isvalid: string);

Begin
repeat
IF (business >10000) THEN
     IF (Customer >= 20) THEN
          Answer := 'Priority Treatment'
     ELSE
          IF (history ='y') THEN
               Answer := 'Priority Treatment'
                isvalid :='true'
     ELSE
               IF (History :='n') THEN
                   Answer := 'Normal Treatment'
                    isvalid :='true'
               Else
                    isvalid :='false';
ELSE Answer := 'Normal Treatment';

until isvalid = 'false'

END;

--
Thomas Sweeney
----------------------------
Praxis Int Homepage:- www.Praxis.4t.com
------------------------------------------------------------------
email me at :- thomas_swee...@email.com
--------------------------------------------------------------------

 

Re:Can someone help?


Tommy wrote in <8rdnk2$bl...@news6.svr.pol.co.uk>...

Quote
>Could anyone tell me what I'm doing wrong with the following
procedure?

>I get a ';' expected error when I try to run the program and it
points to
>the first occurrence of isvalid -'true'

You probably mean:

Procedure Calculate_Customer_Status (VAR business,customer: real; VAR
History,answer,isvalid: string);

Begin
repeat
IF (business >10000) THEN
     IF (Customer >= 20) THEN
          Answer := 'Priority Treatment'
     ELSE
          IF (history ='y') THEN BEGIN
                 Answer := 'Priority Treatment';
                  isvalid :='true'
               END
     ELSE
               IF (History :='n') THEN BEGIN
                     Answer := 'Normal Treatment';
                      isvalid :='true'
                   END
               Else
                    isvalid :='false';
ELSE Answer := 'Normal Treatment';

until isvalid = 'false'

END;

-- (A would-be signature delimiter of OE)
Raimo Suonio, Helsinki, Finland
http://www.nic.fi/%7Ersuonio/
Oikeinkirjoitusohjeita news- ja web-kirjoittajille:
http://www.nic.fi/%7Ersuonio/oikeinkirjoitus/

Re:Can someone help?


 In <8rdnk2$bl...@news6.svr.pol.co.uk>, Tommy
 <Tho...@sweeneyt.freeserve.co.uk> wrote
Quote
>Could anyone tell me what I'm doing wrong with the following procedure?

>I get a ';' expected error when I try to run the program and it points to
>the first occurrence of isvalid -'true'

>I can get this rather simple routine to work fine under VB but I'm just
>learning Pascal so any help would be highly appreciated.

>Procedure Calculate_Customer_Status (VAR business,customer: real; VAR
>History,answer,isvalid: string);

>Begin
>repeat
>IF (business >10000) THEN
>     IF (Customer >= 20) THEN
>          Answer := 'Priority Treatment'
>     ELSE

 This is where your problems start.

 If you have multiple statements within an if/then/else part you have to
 enclose them with a begin end pair and put a ; at the end of each line

Quote
>          IF (history ='y') THEN
>               Answer := 'Priority Treatment'
>                isvalid :='true'
>     ELSE

 should read
            IF (history='y') THEN
            BEGIN
                 Answer := 'Priority Treatment';
                 isvalid := 'true';
            END
       ELSE

 You'll need to do the same with the next block as well.

 BTW, as isvalid takes the values true or false then you'd save some
 storage space by using BOOLEAN values rather than a string.

--
Pedt Scragg     http://signpost-design.co.uk/   ODP Editor: http://dmoz.org/

"If you don't need a lot of space/bandwidth then why are you paying for it" ?

Re:Can someone help?


You need to enclose some of your statements between Begin
and End pairs. For instance, in an if statement when you have
more than one statement to be executed on the condition. If
it's only one statement then you don't need to do this.

Hugh

Quote
"Tommy" <Tho...@sweeneyt.freeserve.co.uk> wrote in message

news:8rdnk2$blf$1@news6.svr.pol.co.uk...
Quote
> Could anyone tell me what I'm doing wrong with the following procedure?

> I get a ';' expected error when I try to run the program and it points to
> the first occurrence of isvalid -'true'

> I can get this rather simple routine to work fine under VB but I'm just
> learning Pascal so any help would be highly appreciated.

> thanks

> Procedure Calculate_Customer_Status (VAR business,customer: real; VAR
> History,answer,isvalid: string);

> Begin
> repeat
> IF (business >10000) THEN
>      IF (Customer >= 20) THEN
>           Answer := 'Priority Treatment'
>      ELSE
>           IF (history ='y') THEN
>                Answer := 'Priority Treatment'
>                 isvalid :='true'
>      ELSE
>                IF (History :='n') THEN
>                    Answer := 'Normal Treatment'
>                     isvalid :='true'
>                Else
>                     isvalid :='false';
> ELSE Answer := 'Normal Treatment';

> until isvalid = 'false'

> END;

> --
> Thomas Sweeney
> ----------------------------
> Praxis Int Homepage:- www.Praxis.4t.com
> ------------------------------------------------------------------
> email me at :- thomas_swee...@email.com
> --------------------------------------------------------------------

Re:Can someone help?


I just noticed another problem. Why are you looping until
isvalid = false ? In fact, why are you looping at all? Your
code looks to me as if it will result in an infinite loop for
a lot of values of your variables. For instance, what if
business is <= 10000 ? You'll just end up with a loop
that keeps on checking this condition, looping again,
checking it again...etc., without any way for isvalid to
be set to false.

Hugh

Quote
"Hugh Gray" <hugh.a.g...@nospam.opc.shell.com> wrote in message

news:yOGC5.378$SD.4110@wwwserv3.shell.nl...
Quote
> You need to enclose some of your statements between Begin
> and End pairs. For instance, in an if statement when you have
> more than one statement to be executed on the condition. If
> it's only one statement then you don't need to do this.

> Hugh

> "Tommy" <Tho...@sweeneyt.freeserve.co.uk> wrote in message
> news:8rdnk2$blf$1@news6.svr.pol.co.uk...
> > Could anyone tell me what I'm doing wrong with the following procedure?

> > I get a ';' expected error when I try to run the program and it points
to
> > the first occurrence of isvalid -'true'

> > I can get this rather simple routine to work fine under VB but I'm just
> > learning Pascal so any help would be highly appreciated.

> > thanks

> > Procedure Calculate_Customer_Status (VAR business,customer: real; VAR
> > History,answer,isvalid: string);

> > Begin
> > repeat
> > IF (business >10000) THEN
> >      IF (Customer >= 20) THEN
> >           Answer := 'Priority Treatment'
> >      ELSE
> >           IF (history ='y') THEN
> >                Answer := 'Priority Treatment'
> >                 isvalid :='true'
> >      ELSE
> >                IF (History :='n') THEN
> >                    Answer := 'Normal Treatment'
> >                     isvalid :='true'
> >                Else
> >                     isvalid :='false';
> > ELSE Answer := 'Normal Treatment';

> > until isvalid = 'false'

> > END;

> > --
> > Thomas Sweeney
> > ----------------------------
> > Praxis Int Homepage:- www.Praxis.4t.com
> > ------------------------------------------------------------------
> > email me at :- thomas_swee...@email.com
> > --------------------------------------------------------------------

Re:Can someone help?


I'd just like to thank everyone for their help on this.

And a special thanks to Hugh, ("You'll just end up with a loop
that keeps on checking this condition, looping again,
checking it again...etc., without any way for isvalid to
be set to false.")  I hadn't noticed that (I feel like a right idiot!). It
looks as though I'm just gonna have to bite the bullet and buy a half decent
Pascal book.

Once again - Thanks Everyone, you've been very helpful.

Thomas

Quote
"Hugh Gray" <hugh.a.g...@nospam.opc.shell.com> wrote in message

news:CXGC5.379$SD.4225@wwwserv3.shell.nl...
Quote
> I just noticed another problem. Why are you looping until
> isvalid = false ? In fact, why are you looping at all? Your
> code looks to me as if it will result in an infinite loop for
> a lot of values of your variables. For instance, what if
> business is <= 10000 ? You'll just end up with a loop
> that keeps on checking this condition, looping again,
> checking it again...etc., without any way for isvalid to
> be set to false.

> Hugh

> "Hugh Gray" <hugh.a.g...@nospam.opc.shell.com> wrote in message
> news:yOGC5.378$SD.4110@wwwserv3.shell.nl...
> > You need to enclose some of your statements between Begin
> > and End pairs. For instance, in an if statement when you have
> > more than one statement to be executed on the condition. If
> > it's only one statement then you don't need to do this.

> > Hugh

> > "Tommy" <Tho...@sweeneyt.freeserve.co.uk> wrote in message
> > news:8rdnk2$blf$1@news6.svr.pol.co.uk...
> > > Could anyone tell me what I'm doing wrong with the following
procedure?

> > > I get a ';' expected error when I try to run the program and it points
> to
> > > the first occurrence of isvalid -'true'

> > > I can get this rather simple routine to work fine under VB but I'm
just
> > > learning Pascal so any help would be highly appreciated.

> > > thanks

> > > Procedure Calculate_Customer_Status (VAR business,customer: real; VAR
> > > History,answer,isvalid: string);

> > > Begin
> > > repeat
> > > IF (business >10000) THEN
> > >      IF (Customer >= 20) THEN
> > >           Answer := 'Priority Treatment'
> > >      ELSE
> > >           IF (history ='y') THEN
> > >                Answer := 'Priority Treatment'
> > >                 isvalid :='true'
> > >      ELSE
> > >                IF (History :='n') THEN
> > >                    Answer := 'Normal Treatment'
> > >                     isvalid :='true'
> > >                Else
> > >                     isvalid :='false';
> > > ELSE Answer := 'Normal Treatment';

> > > until isvalid = 'false'

> > > END;

> > > --
> > > Thomas Sweeney
> > > ----------------------------
> > > Praxis Int Homepage:- www.Praxis.4t.com
> > > ------------------------------------------------------------------
> > > email me at :- thomas_swee...@email.com
> > > --------------------------------------------------------------------

Other Threads