Microsoft KB Archive/176895

= BUG: FOR EACH Fails to Remove All Objects =

Article ID: 176895

Article Last Modified on 12/11/1999

-

APPLIES TO


 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 5.0a
 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q176895



SYMPTOMS
When you use FOR EACH in Visual FoxPro version 5.x as a looping mechanism to remove all objects in a container, only half of the objects in the container are removed.



RESOLUTION
Wrap the FOR EACH command with the DO WHILE command. The following sample code is the workaround for the problem illustrated in the Steps to Reproduce Behavior section.

Replace the code in the Click method with the following code: DO WHILE Thisform.CommandGroup1.ButtonCount <> 0 FOR EACH oControl IN Thisform.CommandGroup1.Buttons Thisform.CommandGroup1.RemoveObject(oControl.Name) ENDFOR ENDDO



STATUS
Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.



Steps to Reproduce Behavior
 Create a new form. Add a CommandGroup to the form and set the following properties:

Height = 180 Width = 96

ButtonCount = 6

 Add a second Commandbutton to the form and set the following property:

Caption = "Click Me"

  In the Click method of the Commandbutton, type the following code: FOR EACH oControl IN Thisform.CommandGroup1.Buttons Thisform.CommandGroup1.RemoveObject(oControl.Name) ENDFOR  Run the form, and click the "Click Me" button.</ol>

NOTE: Only three buttons in the CommandGroup are deleted and the other three still show up.

Additional query words: container remove kbvfp500 kbvfp500a kbvfp600

Keywords: kbbug KB176895

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.