Results 1 to 3 of 3

Thread: Code

  1. #1
    zingaro
    Guest

    Code

    Hi There
    I am new to VB programming and would like to have a code which allows me to count the number of Vb controls eg like text box within a given window.
    Help is highly appreciated

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    sample :

    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim c As Control
    3.     Dim iTxt As Integer
    4.     Dim iLbl As Integer
    5.     Dim iCmdBtn As Integer
    6.     '.
    7.     '.
    8.     '.
    9.    
    10.     For Each c In Me
    11.         If TypeOf c Is TextBox Then iTxt = iTxt + 1
    12.         If TypeOf c Is Label Then iLbl = iLbl + 1
    13.         If TypeOf c Is CommandButton Then iCmdBtn = iCmdBtn + 1
    14.        
    15.         '.
    16.         '.
    17.         '.
    18.     Next c
    19.     Debug.Print "Textbox count: " & iTxt
    20.     Debug.Print "Label count: " & iLbl
    21.     Debug.Print "Command Button count: " & iCmdBtn
    22. End Sub

  3. #3
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    VB Code:
    1. Private Sub Form_Load()
    2.     MsgBox numberOfControlsOnForm(Me)
    3.     MsgBox numberOfControlsOnForm(frmSomeOtherForm)
    4. End Sub
    5.  
    6. Public Function numberOfControlsOnForm(frmName As Form) As Long
    7.     Dim x As Control, i As Long
    8.     For Each x In frmName.Controls
    9.         i = i + 1
    10.     Next
    11.     numberOfControlsOnForm = i
    12. End Function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width