BUG: Forms.Count and Controls.Count Collections Cause Error

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

SYMPTOMS

When accessing the Count property of either the Forms or the Controls collection, the following error is generated:

   Error 450: "Wrong number of arguments or invalid property assignment"

RESOLUTION

The following code sample shows how to use the two functions below to get the Forms Count and Controls Count values without producing an error.

  1. Create a new Windows CE Project in Visual Basic 5.0. Form1 is created by default.

  2. Add a CommandButton to Form1.

  3. Add the following code to Form1:

          Option Explicit
          Private Sub Command1_Click()
    
              'MsgBox Forms.Count and Controls.Count generate an error,
              'so use the following Functions instead.
              MsgBox "There are/is " & FormsCount & " form(s) loaded"
              MsgBox "Form(0) contains " & ControlsCount & " control(s)"
          End Sub
    
          Private Function FormsCount()
              '===========================================
              'Work around for Forms.Count bug.
              'Returns the number of loaded forms.
              '===========================================
              Dim iFormCount
              Dim sDummy
              On Error Resume Next
              Do
                  sDummy = Forms(iFormCount).Name
                  If Err.Number <> 0 Then
                      FormsCount = iFormCount
                      Exit Do
                  End If
                  iFormCount = iFormCount + 1
              Loop
          End Function
    
          Private Function ControlsCount()
              '===============================================
              'Work around for Controls.Count bug.
              'Returns the number of Controls on the form.
              '===============================================
              Dim iControlsCount
              Dim sDummy
              On Error Resume Next
              Do
                  sDummy = Controls(iControlsCount).Name
                  If Err.Number <> 0 Then
                      ControlsCount = iControlsCount
                      Exit Do
                  End If
                  iControlsCount = iControlsCount + 1
              Loop
          End Function
    
    

  4. Press the F5 key to run the project.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Steps to Reproduce Behavior

WARNING: The following steps will cause an exception error to occur.

  1. Create a new Windows CE Project in Visual Basic 5.0. Form1 is created by default.

  2. Add a CommandButton to Form1.

  3. Add the following code to Form1:

          Private Sub Command1_Click()
    
              'MsgBox Forms.Count and Controls.Count generate
              'an error as shown in the following code:
              MsgBox "There are/is " & Forms.Count & " form(s) loaded"
              MsgBox "Form(0) contains " & Controls.Count & " control(s)"
          End Sub
    
    

  4. Press the F5 key to run the project.

(c) Microsoft Corporation 1998, All Rights Reserved. Contributions by Mike Dixon, Microsoft Corporation
Keywords          : vb5all vbce kberrmsg
Version           : WINDOWS:1.0
Platform          : WINDOWS
Issue type        : kbbug
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 5, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.