Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Interesting trap with ELS instead of ELSE

Status
Not open for further replies.

dgfletcher

Programmer
Nov 8, 2002
11
US
A quick note. In VFP7
IF
.....
ELS && misspelled
......
ENDIF
seems to function exactly as if the ELS wasn't there.
The compiler doesn't flag it as an error.
If this is known, forgive the post. A quick search didn't show anything posted yet.
Don.
 
It's known and it will fail if the Els is
invoked by the first test failing.

Example:

LOCAL lbTestConditional, lcCurErrHand
lcCurrErrHand = ON("error")

ON ERROR DO Err_Hand WITH ERROR(), MESSAGE(), MESSAGE(1)

lbTestConditional= .T.
TestConditional(lbTestConditional)

lbTestConditional= .F.
TestConditional(lbTestConditional)

ON ERROR &lcCurrErrHand


PROCEDURE TestConditional(lbTestValue)
IF lbTestValue
MESSAGEBOX("Got Here")
els
MESSAGEBOX("Will fail on els")
ENDIF
ENDPROC


PROCEDURE Err_Hand(errnum, errmsg1, errmsg2)

MESSAGEBOX( ;
"Error number "+TRANSFORM(errnum)+CHR(13)+;
"Error message 1 "+errmsg1+CHR(13)+;
"Error message 2 "+errmsg2+CHR(13) ;
)
ENDPROC


'We all must do the hard bits so when we get bit we know where to bite' :)
 
I think there is a breakdown in communication here.

This produces a RUNTIME error in the command window in VFP7 and generates a COMPILE error when compiled.

IF .t.
WAIT "Hi" WINDOW TIMEOUT 3
ELS && misspelled
WAIT "Hi There" WINDOW TIMEOUT 3
ENDIF


However, if you change the condition to FALSE, it RUNS without a RUNTIME error in the command window but it still generates a COMPILE error when compiled.

The reason for not generating a RUNTIME error is probably because if the condition is false, it leaps immediately to the position right after the ENDIF because it doesn't recognize the ELS inside and thinks it is a simple IF/ENDIF statement.





Don


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top