View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Myles[_41_] Myles[_41_] is offline
external usenet poster
 
Posts: 1
Default Bizzare behavior of IF..THEN


Having in times past encountered very freakish behavior of IF...THE
clauses, I now wish to bring up some of my observations for commen
and possible explanation. Below are 4 trumped-up cases each showin
the evaluation, or lack of it, of the conditions set out in eac
routine. Cases A and B are straightforward as they conform to what w
might expect. Namely, there is indication of serial evaluation of al
the conditions- whether met or not.

By contrast, Cases C and D betray the norm, at least seemingly so, a
conditions which should be positively evaluated appear to be untouched
(see the commented annotations for full appreciation).

Case A Case B
'all 4 conds evaluated 'all 4 conds evaluated
Sub test2() Sub test3()
If 4 < 5 Then If 4 < 5 Then 'evaluated
MSGBOX [/b]\"4<5\" *MSGBOX *\"4<5\"
IF 4 3 THEN END IF
*MSGBOX *\"43\" IF 8 10 THEN 'EVALUATED
IF 4 = 4 THEN MSGBOX \"810\"
*MSGBOX *\"4=4\" END IF
ELSE IF 3 = 3 THEN 'EVALUATED
MSGBOX \"OTHER\" *MSGBOX* \"3=3\"
END IF ELSE 'EVALUATED
END IF MSGBOX \"OTHER\"
END IF END IF
END SUB END SUB


CASE C CASE D
* 'NONE IS EVALUATED INCLUDING COND
Sub test1() Sub test4()
If 4 < 5 Then 'evaluated If 12 < 5 Then
MSGBOX* \"4<5\" MSGBOX \"12<5\"
IF 8 10 THEN*'NOT EVALUATED* IF 8 10 THEN
MSGBOX \"810\" MSGBOX \"810\"
IF 3 = 3 THEN *'NOT EVALUATED* IF 3 = 3 THEN *'NOT EVALUATE
MsgBox "3=3" MsgBox "3=3"
Else [b]'not evaluated* Else
MsgBox "other" MsgBox "other"
End If End If
End If End If
End If End If
End Sub End Sub

Bolded MsgBox refers to positive evaluation as it springs to life.

Your comments are welcomed.

Myle

--
Myle
-----------------------------------------------------------------------
Myles's Profile: http://www.excelforum.com/member.php...fo&userid=2874
View this thread: http://www.excelforum.com/showthread.php?threadid=50665