Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How can i count and get the name of objects on a form
Message
 
To
18/09/2002 07:31:54
Atif Saeed Khan
Nextbridge Prvt Ltd.
Lahore, Pakistan
General information
Forum:
Visual Basic
Category:
Database DAO/RDO/ODBC/ADO
Miscellaneous
Thread ID:
00701678
Message ID:
00701696
Views:
20
You may want to try this:
Option Explicit

Private marrTypeName() As String
Private marrCount() As Integer

Private Sub Command1_Click()
Dim ctlX As Control
Dim intI As Integer

    Erase marrTypeName
    Erase marrCount
    
    For Each ctlX In Me.Controls
        intI = AScan(marrTypeName, TypeName(ctlX))
        If intI < 0 Then
            intI = ArrayAdd(marrTypeName, TypeName(ctlX))
            Call ArrayAdd(marrCount, 0)
        End If
        marrCount(intI) = marrCount(intI) + 1
    Next
    
    For intI = LBound(marrTypeName) To UBound(marrTypeName)
        MsgBox marrTypeName(intI) & ": " & marrCount(intI)
    Next intI
End Sub

Public Function ArrayAdd(ByRef parrTableau As Variant, _
                         ByVal pvarValue As Variant, _
                         Optional ByVal pblnPreserve As Boolean = True _
                        ) As Integer
Dim intI As Integer

    On Error Resume Next
    intI = UBound(parrTableau) + 1
    If Err.Number <> 0 Then intI = 0
    On Error GoTo 0

    If pblnPreserve Then
        ReDim Preserve parrTableau(intI)
    Else
        ReDim parrTableau(intI)
    End If

    parrTableau(intI) = pvarValue
    ArrayAdd = intI
End Function

Public Function AScan(ByVal parrTableau As Variant, _
                      ByVal pstrText As String) As Integer
Dim intI As Integer
Dim strElement As Variant

    AScan = -1

    On Error Resume Next
    intI = UBound(parrTableau)
    If Err.Number <> 0 Then Exit Function
    On Error GoTo 0
    
    intI = 0
    For Each strElement In parrTableau
        If UCase$(Trim$(strElement)) = UCase$(Trim$(pstrText)) Then
            AScan = intI
            Exit Function
        End If
        intI = intI + 1
    Next
End Function
>hi to all
>
>i have a problem. i have one form and on that form i have more then one kind of objects. for example i have 2 TEXTBOXES, 3 COMBOBOXES and 4 LABELS objects.now what i want to write such code which can give me the following result.
>
>TEXTBOX = 2
>COMBOBOX = 3
>LABEL = 4
>
>Y I WANT THIS? i want to write a general procedure in module and call it from every form's activate event if that form contain any control define in that pricedure then i can change it's property at the run time. whenever i want.
>
>bye
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com
Previous
Reply
Map
View

Click here to load this message in the networking platform