Microsoft KB Archive/180573

{|
 * width="100%"|

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

 * }

Q180573

-

The information in this article applies to:


 * Microsoft 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.

 Create a new Windows CE Project in Visual Basic 5.0. Form1 is created by default. Add a CommandButton to Form1.  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  Press the F5 key to run the project.

STATUS
Microsoft has confirmed this to be a problem in the Microsoft products that are listed at the beginning of this article.

This problem was corrected in Windows CE Toolkit for Visual Basic 6.0.

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

 Create a new Windows CE Project in Visual Basic 5.0. Form1 is created by default. Add a CommandButton to Form1.  Add the following code to Form1: <pre class="CODESAMP">     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 </li> Press the F5 key to run the project.</li></ol>

© Microsoft Corporation 1999, All Rights Reserved.

Contributions by Mike Dixon, Microsoft Corporation

Additional query words: wince vbce vbce5 vbce6

Keywords : kbToolkit kbVBp kbVBp500bug kbVBp600fix kbOSWinCEsearch kbOSWinCE100 kbGrpDSVB

Issue type : kbbug

Technology : kbVBSearch kbAudDeveloper kbWinCETKVBSearch kbWinCESearch kbWinCETK100VB500