G
Guest
Although HasChildShapeRange is listed as boolean in the object browser, when
HasChildShapeRange is True, its value is 1, not -1. Consequently, IF
statements may not work as expected.
To illustrate the problem, put a couple of shapes on a slide and group them,
then select one of the group. That makes HasChildShapeRange true.
(ChildShapeRange returns the members of a group that are selected.) Insert
the following into a module, and run it:
Sub Play()
With ActiveWindow.Selection
If .HasChildShapeRange Then
Debug.Print "Yes"
Else
Debug.Print "No"
End If
If .HasChildShapeRange = True Then
Debug.Print "Yes"
Else
Debug.Print "No"
End If
If .HasChildShapeRange = False Then
Debug.Print "No"
Else
Debug.Print "Yes"
End If
If Not .HasChildShapeRange Then
Debug.Print "No"
Else
Debug.Print "Yes"
End If
End With
End Sub
Because HasChildShapeRange is true, the expected output would be Yes, Yes,
No, No, but the actual output is Yes, No, Yes, No. The expression
"If .HasChildShapeRange = True Then"
evaluates as false because 1 is not equal to -1 (the value of True). The
expression
"If Not .HasChildShapeRange Then"
always evaluates as True. (If HasChildShapeRange is False, it equals 0;
"Not 0" is -1, or True. If HasChildShapeRange is True, it equals 1; "Not 1"
is also True. Only "Not -1" is 0, or False.)
Recommendation:
Use "If .HasChildShapeRange Then" to test if the expression is True.
Use "If .HasChildShapeRange = False Then" to test if it is False.
Chris
HasChildShapeRange is True, its value is 1, not -1. Consequently, IF
statements may not work as expected.
To illustrate the problem, put a couple of shapes on a slide and group them,
then select one of the group. That makes HasChildShapeRange true.
(ChildShapeRange returns the members of a group that are selected.) Insert
the following into a module, and run it:
Sub Play()
With ActiveWindow.Selection
If .HasChildShapeRange Then
Debug.Print "Yes"
Else
Debug.Print "No"
End If
If .HasChildShapeRange = True Then
Debug.Print "Yes"
Else
Debug.Print "No"
End If
If .HasChildShapeRange = False Then
Debug.Print "No"
Else
Debug.Print "Yes"
End If
If Not .HasChildShapeRange Then
Debug.Print "No"
Else
Debug.Print "Yes"
End If
End With
End Sub
Because HasChildShapeRange is true, the expected output would be Yes, Yes,
No, No, but the actual output is Yes, No, Yes, No. The expression
"If .HasChildShapeRange = True Then"
evaluates as false because 1 is not equal to -1 (the value of True). The
expression
"If Not .HasChildShapeRange Then"
always evaluates as True. (If HasChildShapeRange is False, it equals 0;
"Not 0" is -1, or True. If HasChildShapeRange is True, it equals 1; "Not 1"
is also True. Only "Not -1" is 0, or False.)
Recommendation:
Use "If .HasChildShapeRange Then" to test if the expression is True.
Use "If .HasChildShapeRange = False Then" to test if it is False.
Chris