Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Is it possible to nest IF THEN ENDIF statements? I am having an issue doing it in my app:
IF condition1 THEN
IF condition2 THEN
do something
ENDIF //this should end condition 2 becasue it is nested.
ENDIF //this should end condition 1 because it is the outside set
This seems to create an issue when condition 1 is not met due to an extra ENDIF it can't handle. This leads me to believe it is using the first ENDIF statement rather than the second.
Anybody have ideas on getting this to work?
Yup nesting IFs is certainly possible. You could try using and AND to combine the IFs together like this:
IF Field1='ABC' AND Field2=25 THEN
END IF
Well so really they are not "nested". A nested IF statement would exist completely inside another. But the approachg you suggested does solve my problem. Thanks for the assist!
True, using the AND isn't really a nested IF. But true nested IFs should work perfectly and I've done so more times than I can count. No idea why they aren't working for you. I just rand this and it worked as expected:
IF 1=1 THEN
IF 1=1 THEN
trace hello world;
ENDIF
ENDIF
Out of interest, try changing ENDIF for END IF (with a space) as I normally use the latter and it wouldn't be the first time I've seen a strange bug like that in QV.