FIX: Forms.Count and Controls.Count Collections Cause ErrorID: Q180573
|
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"
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.
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
Microsoft has confirmed this to be a problem in the Microsoft products listed
at the beginning of this article.
This problem was corrected in Windows CE Toolkit for Visual Basic 6.0.
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
© Microsoft Corporation 1999, All Rights Reserved.
Contributions by Mike Dixon, Microsoft Corporation
Additional query words: wince vbce vbce5 vbce6
Keywords : kbToolkit kbVBp kbVBp500bug kbVBp600fix kbWinCE kbWinCE100 kbGrpVB
Version : WINDOWS:1.0
Platform : WINDOWS
Issue type : kbbug
Last Reviewed: February 25, 1999