Focal Point
[SOLVED] IF ELSE SYNTAX ERROR

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/3687051776

July 09, 2015, 10:03 AM
siddu1790
[SOLVED] IF ELSE SYNTAX ERROR
i am using the following if else statement
-SET &w = IF &Text.&I.A150 CONTAINS "some text"
THEN PRINT "hello"
ELSE PRINT "helloq1";

i dont understand what is the error
its giving IF ..THEN..ELSE synatx error
please help

This message has been edited. Last edited by: <Kathryn Henning>,


WEBFOCUS 8.0
July 09, 2015, 10:10 AM
Francis Mariani
I won't debug the rest of the -SET statement, but since it is a multi-line Dialogue Manager command, each subsequent line must begin with "- ".

-SET &w = IF &Text.&I.A150 CONTAINS "some text"
- THEN PRINT "hello"
- ELSE PRINT "helloq1";



Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
July 09, 2015, 10:14 AM
Tomsweb
I don't think you can declare the size of an amper variable. Furthermore, you are using an indexed variable. Does &I have a value?

Please declare &I=1; and remove A150. Then try it and see what happens. Also put -SET &ECHO=ALL at the very top of your code to observe this result in detail.
July 09, 2015, 10:16 AM
Tomsweb
On the other hand, I might be crazy.


Tomsweb
WebFOCUS 8.1.05M, 8.2.x
APP Studio, Developer Studio, InfoAssist, Dashboards, charts & reports
Apache Tomcat/8.0.36
July 09, 2015, 10:17 AM
siddu1790
Thanks for the reply Francis , but i am still having the same error

&Text.&I.A80 = "TEXt TEXT TEXT some text TEXT TEXT"

can i use the below condition

-SET &w = IF &Text.&I.A150 CONTAINS "some text"
-THEN PRINT "hello"
-ELSE PRINT "helloq1";

ERROR MESSAGE :-
0 ERROR AT OR NEAR LINE 29 IN PROCEDURE ADHOCRQ FOCEXEC *
(FOC266) IF .. THEN .. ELSE .. SYNTAX ERROR


WEBFOCUS 8.0
July 09, 2015, 10:20 AM
John_Edwards
PRINT in that context is new to me. Is that correct syntax?

For giggles remove the two PRINTs. That's what I would have done. Should set &w to the correct value.

What does it look like in the code with the amper-variables resolved by the way? -SET ECHO=ALL at the top and show us what the command going to the parser looks like.

This message has been edited. Last edited by: John_Edwards,



July 09, 2015, 10:24 AM
Tomsweb
Instead of the print command where you've coded put GOTO PrintIt. The code a -PrintIt label, where you'd code the print XXX command, followed by -EXIT to leave the program.


Tomsweb
WebFOCUS 8.1.05M, 8.2.x
APP Studio, Developer Studio, InfoAssist, Dashboards, charts & reports
Apache Tomcat/8.0.36
July 09, 2015, 10:28 AM
siddu1790
i have written the following program

-SET &MAS_COUNT = &LINES;
-REPEAT :MAS_READ FOR &I FROM 1 TO &MAS_COUNT;
-READ mymaster &Text.&I.A80
-SET &w = IF &Text.&I CONTAINS "sometext"
-THEN GOTO Printit
-ELSE GOTO REPEAT;
-*IF &IORETURN NE 0 THEN GOTO END_READ;
-TYPE text =&Text.&I.A80
-:MAS_READ

-Printit
PRINT "Hello"
-EXIT

If it dosent match i want to continue the looping


WEBFOCUS 8.0
July 09, 2015, 10:35 AM
Francis Mariani
It looks like your ELSE statement does not have "- " before it.

And PRINT is not a Dialogue Manager command.


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
July 09, 2015, 11:15 AM
Tomsweb
Below the -PrintIt section you have only 2 options for output....
1. Issue a table request to print a report, or
2. Issue a -TYPE &variable . Or, -TYPE Hello

Basically as Francis just stated.


Tomsweb
WebFOCUS 8.1.05M, 8.2.x
APP Studio, Developer Studio, InfoAssist, Dashboards, charts & reports
Apache Tomcat/8.0.36
July 09, 2015, 11:20 AM
siddu1790
i have written the following program

-SET &MAS_COUNT = &LINES;
-REPEAT :MAS_READ FOR &I FROM 1 TO &MAS_COUNT;
-READ mymaster &Text.&I.A80
-SET &w = IF &Text.&I CONTAINS "sometext" THEN GOTO Printit ELSE GOTO REPEAT;
-*IF &IORETURN NE 0 THEN GOTO END_READ;
-TYPE text =&Text.&I.A80
-:MAS_READ

-Printit
-TYPE hello
-EXIT

My question is is the IF statement correst?? can i issue GOTO REPEAT in the ELSE ??

As my Error is

0 ERROR AT OR NEAR LINE 29 IN PROCEDURE ADHOCRQ FOCEXEC *
(FOC266) IF .. THEN .. ELSE .. SYNTAX ERROR

My line 29 is -SET &w = IF &Text.&I CONTAINS "sometext" THEN GOTO Printit ELSE GOTO REPEAT;


WEBFOCUS 8.0
July 09, 2015, 11:29 AM
Tomsweb
What do you with the &w variable? It seems to me you should code: -IF &text.&I eq ... Then GOTO ...ELSE ...


Tomsweb
WebFOCUS 8.1.05M, 8.2.x
APP Studio, Developer Studio, InfoAssist, Dashboards, charts & reports
Apache Tomcat/8.0.36
July 09, 2015, 11:46 AM
siddu1790
SET &w = IF &Text.&I CONTAINS 'sometext' THEN GOTO Printit ELSE GOTO REPEAT;

I have used single codes instead of double and it worked..


WEBFOCUS 8.0
July 09, 2015, 06:02 PM
Waz
You shouldn't do a -SET when using an IF THEN ELSE with GOTO's, it is illogical.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

July 10, 2015, 08:48 AM
j.gross
It's apparent the Dialog Manager directive you are looking for is
-IF ... ;

rather than
-SET ... ;


Look it up.


- Jack Gross
WF through 8.1.05
July 10, 2015, 09:58 AM
siddu1790
yes j.gross, i have corrected it and works fine..thanks


WEBFOCUS 8.0
July 10, 2015, 11:33 AM
George Patton
I'm with Waz. You should use the value in &w as the value for the GOTO:

-SET &w = IF &Text.&I CONTAINS 'sometext' THEN 1 ELSE 0;
-IF &w EQ 1 GOTO Printit ELSE GOTO REPEAT;

Jack, as usual, has the more succinct version. Mine works if you want to use &w elsewhere.


WebFOCUS 7.7.05 Windows, Linux, DB2, IBM Lotus Notes, Firebird, Lotus Symphony/OpenOffice. Outputs PDF, Excel 2007 (for OpenOffice integration), WP
July 10, 2015, 01:07 PM
Tomsweb
There are several good examples here for you to follow, but here is an approach I've coded in the past.

To accommodate your use of the &W variable...

-SET &W = IF &AGE LE 100 THEN YOUNG ELSE OLD;
-GOTO &W

-YOUNG
-**** DO SOMETHING WITH THE YOUNG
ETC.
-GOTO OUTT

-OLD
-**** DO SOMETHING WITH OLD
ETC.

-OUTT
-EXIT

Another, perhaps with less coding...

-IF &AGE LE 100 THEN GOTO YOUNG ELSE IF &AGE GT 100 GOTO OLD;

Use the -YOUNG and -OLD code I created above

Good Luck


Tomsweb
WebFOCUS 8.1.05M, 8.2.x
APP Studio, Developer Studio, InfoAssist, Dashboards, charts & reports
Apache Tomcat/8.0.36