Announcement

Collapse
No announcement yet.

Error 447 If Expected

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error 447 If Expected

    Please add your comments and suggestions as a Reply to this thread.





    PB/WIN - Error 447 - IF expected
    IF expected - The compiler found an END IF or an EXIT IF statement without a beginning IF statement defined.

    Last edited by Gary Beene; 28 Oct 2014, 08:06 PM.

  • #2
    Suggested addition information

    Add the following:
    Code:
    This error is also generated with a legitimate IF THEN/END IF block 
    containing one of the following:
    DO/LOOP block missing LOOP
    WHILE/WEND block missing WEND 
    SELECT CASE/END SELECT block missing END SELECT
    FOR/NEXT block missing NEXT
    
    When these statement are missing inside of another block, the best the 
    compiler can do is let you know there is an error within the block as 
    it cannot determine which code should be in which block. This list offers
    suggestions to help find the error.
    Test code: loopconditionalerrors.bas
    Code:
    #COMPILE EXE         'final posted version of this testing code-testing  complete
    #DIM ALL
    
    FUNCTION PBMAIN () AS LONG
      LOCAL d, f, w, i, s, u AS LONG
      LOCAL boring AS STRING
      LOCAL tWin AS DWORD
      RANDOMIZE TIMER
      TXT.WINDOW("Loop-conditional error check", 5,5, 40,90) TO tWin
      TXT.PRINT
      d=1
      f=2
      w=3
      i=4
      s=5
      TXT.PRINT "Inside a DO/LOOP"
      DO
        IF s>4 THEN
          INCR d
          TXT.PRINT " TEST  1 Missing END IF inside a DO/LOOP error 448 message is misleading"
        END IF                'without this compiler error 448:"DO loop expected"
        FOR u=1 TO 3
          f=d
          TXT.PRINT " TEST  2 Missing NEXT inside a DO/LOOP error 448 message is misleading"
          EXIT FOR
        NEXT u                'without this compiler error 448:"DO loop expected"
        WHILE ISTRUE w
          TXT.PRINT " TEST  3 Correct error message but the cursor can be far afield!!"
          w=0
        WEND                  'without this compiler error 456:"LOOP/WEND expected-no issue"
        SELECT CASE AS LONG s
          CASE 5
            TXT.PRINT " TEST  4 Missing END SELECT inside a DO/LOOP error 448 message is misleading"
          CASE ELSE
        END SELECT            'without this compiler error 448:"DO loop expected"
      LOOP UNTIL d=2
    
      TXT.PRINT
      TXT.PRINT "Inside a WHILE/WEND"
      w=3
      WHILE w=3
        IF s>4 THEN
          INCR d
          TXT.PRINT " TEST  5 Missing END IF inside a WHILE/WEND error 448 message is misleading"
        END IF              'without this compiler error 448:"DO loop expected"
        FOR u=1 TO 3
          f=d
          TXT.PRINT " TEST  6 Missing NEXT inside a WHILE/WEND error 448 message is misleading"
          EXIT FOR
        NEXT u              'without this compiler error 448:"DO loop expected"
        DO
          TXT.PRINT " TEST  7 Correct error message but the cursor can be far afield!!"
          EXIT DO
        LOOP                'without this compiler error 456:"LOOP/WEND expected"
        SELECT CASE AS LONG s
          CASE 5
            TXT.PRINT " TEST  8 Missing END SELECT inside a WHILE/WEND error 448 message is misleading"
          CASE ELSE
        END SELECT            'without this compiler error 448:"DO loop expected"
        EXIT LOOP
      WEND
    
      TXT.PRINT
      TXT.PRINT "Inside a FOR/NEXT"
      w=0
      FOR u=1 TO 1
        IF s>4 THEN
          INCR d
          TXT.PRINT " TEST  9 Missing END IF inside a FOR/NEXT error 451 message is misleading"
        END IF              'without this compiler error 451:"FOR loop expected"
        WHILE ISFALSE w
          TXT.PRINT " TEST 10 Missing WEND inside a FOR/NEXT error 451 message is misleading"
          w=3
        WEND                'without this compiler error 451:"FOR loop expected"
        SELECT CASE AS LONG s
          CASE 5
            TXT.PRINT " TEST 11 Missing END SELECT inside a FOR/NEXT error 451 message is misleading"
          CASE ELSE
        END SELECT          'without this compiler error 451:"FOR loop expected"
        DO
          TXT.PRINT " TEST 12 Missing LOOP inside a FOR/NEXT error 451 message is misleading"
          EXIT DO
        LOOP                'without this compiler error 451:"FOR loop expected"
      NEXT u
    
      TXT.PRINT
      TXT.PRINT "Inside an IF THEN/END IF"
      w=0
      IF ISTRUE i THEN
        FOR u=1 TO 3
          f=d
          TXT.PRINT " TEST 13 Missing NEXT inside a IF THEN/END IF error 447 message is misleading"
          EXIT FOR
        NEXT u              'without this compiler error 447:"IF expected"
        DO
          TXT.PRINT " TEST 14 Missing LOOP inside a IF THEN/END IF error 447 message is misleading"
          EXIT DO
        LOOP                'without this compiler error 447:"IF expected"
        SELECT CASE AS LONG s
          CASE 5
            TXT.PRINT " TEST 15 Missing END SELECT inside a IF THEN/END IF error 447 message is misleading"
          CASE ELSE
        END SELECT          'without this compiler error 447:"IF expected"
        WHILE ISFALSE w
          TXT.PRINT " TEST 16 Missing WEND inside a IF THEN/END IF error 447 message is misleading"
          w=3
        WEND                'without this compiler error 447:"IF expected"
      END IF
    
      TXT.PRINT
      TXT.PRINT "Inside a SELECT CASE/END SELECT"
      w=0
      SELECT CASE AS LONG s
        CASE 5
          IF s>4 THEN
            INCR d
            TXT.PRINT " TEST 17 Missing END IF inside a SELECT CASE/END SELECT error 449 message is misleading"
          END IF              'without this compiler error 449:"SELECT expected"
          FOR u=1 TO 3
            f=d
            TXT.PRINT " TEST 18 Missing NEXT inside a SELECT CASE/END SELECT error 449 message is misleading"
            EXIT FOR
          NEXT u              'without this compiler error 449:"SELECT expected"
          DO
            TXT.PRINT " TEST 19 Missing LOOP inside a SELECT CASE/END SELECT error 449 message is misleading"
            EXIT DO
          LOOP                'without this compiler error 449:"SELECT expected"
          WHILE ISFALSE w
            TXT.PRINT " TEST 20 Missing WEND inside a SELECT CASE/END SELECT error 449 message is misleading"
            w=3
          WEND              'without this compiler error 449:"SELECT expected"
        CASE ELSE
    
      END SELECT
    
      boring= TXT.WAITKEY$
      TXT.END
    
    END FUNCTION
    An image of the code output can be found in this thread.
    Last edited by Rodney Hicks; 31 Aug 2014, 03:57 AM. Reason: add info, change code, add link
    Rod
    "To every unsung hero in the universe
    To those who roam the skies and those who roam the earth
    To all good men of reason may they never thirst " - from "Heaven Help the Devil" by G. Lightfoot

    Comment


    • #3
      This error pops up when there is a syntax error, specifically code following a THEN statement in an IF block. It can be difficult to find in complicated code because you are looking at the beginning of the lines searching for where the IF should be.
      Code:
      #COMPILE EXE
      #DIM ALL
      
      FUNCTION PBMAIN () AS LONG
        LOCAL gWin, c, x, y, j, k AS LONG
        GRAPHIC WINDOW NEW "IF expected Error 447", 100,100,400,200 TO gWin
        GRAPHIC CLEAR %BLACK
        GRAPHIC COLOR %WHITE,-2
        c=100
        x=200
        y=5
        FOR k=1 TO 20
          IF c>y AND x>c THEN
            IF y*c>x THEN k              ' syntax error is here
              GRAPHIC PRINT "So What!"
              INCR j
              IF j=5 THEN
                c-= 50
              END IF
            END IF
          END IF   ' compiler points here with - Error 447 in C:\PBWin10\Programs\if_error.bas(22:005):  IF expected
        NEXT k
      
        GRAPHIC WAITKEY$
        GRAPHIC WINDOW END
      END FUNCTION
      Rod
      "To every unsung hero in the universe
      To those who roam the skies and those who roam the earth
      To all good men of reason may they never thirst " - from "Heaven Help the Devil" by G. Lightfoot

      Comment


      • #4
        I had one of these mismached IF/ENDIF problems pop up recently. I tried commenting out the line that the compiler flagged as the error and the error jumped over to another DO/LOOP section that looked fine so I commented out that flagged line and a different IF/ENDIF was flagged. It was just jumping from one code block to another. Eventually what fixed it was to put all the lines back in to get the original error and comment out more and more of the entire IF/ENDIF code block until it compiled. At that point I had a smaller section of code to look through until the culprit was found.

        Comment


        • #5
          I think this error is missed because in a single line IF statement code is expected in that position and the compiler doesn't know that it is not a single line statement at that point.
          I found this the hard way as well.
          Rod
          "To every unsung hero in the universe
          To those who roam the skies and those who roam the earth
          To all good men of reason may they never thirst " - from "Heaven Help the Devil" by G. Lightfoot

          Comment


          • #6
            My rule is 'when you write the 'IF' or similar statements - you write the END IF next. And then fill in the gaps.

            I use macros a lot - say no more!!!

            I do wish I obeyed my own rule sometimes.

            Frank's 'comment out until you get a compile' is a good technique which I also use
            [I]I made a coding error once - but fortunately I fixed it before anyone noticed[/I]
            Kerry Farmer

            Comment

            Working...
            X