DOC: For Each ... Next Statement Does Not Work for Collections

Last reviewed: February 4, 1998
Article ID: Q180487
The information in this article applies to:
  • Windows CE Toolkit for Visual Basic 5.0, version 1.0

SUMMARY

In Books Online, the description for the "For Each ... Next" statement is as follows:

   "Repeats a group of statements for each element in an array or
   collection."

However, this is not true for collections because you cannot declare a collection in Microsoft Windows CE Toolkit for Visual Basic 5.0 (VBCE).

MORE INFORMATION

Unlike what's indicated in Books Online, the following code will not work in VBCE because neither the Dim statement's As clause nor New clause are supported:

   Private Sub Command1_Click()
      Dim col As New Collection
      Dim vnt
      col.Add "Item1"
      col.Add "Item2"
      col.Add "Item3"
      col.Add "Item4"
      For Each vnt In col
          MsgBox vnt
      Next
   End Sub
Keywords          : vb5all vbce kbdocerr
Version           : WINDOWS:1.0
Platform          : WINDOWS
Issue type        : kbdocerr
Solution Type     : kbpending


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 4, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.