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
Printable View
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
sample :
VB Code:
Private Sub Command1_Click() Dim c As Control Dim iTxt As Integer Dim iLbl As Integer Dim iCmdBtn As Integer '. '. '. For Each c In Me If TypeOf c Is TextBox Then iTxt = iTxt + 1 If TypeOf c Is Label Then iLbl = iLbl + 1 If TypeOf c Is CommandButton Then iCmdBtn = iCmdBtn + 1 '. '. '. Next c Debug.Print "Textbox count: " & iTxt Debug.Print "Label count: " & iLbl Debug.Print "Command Button count: " & iCmdBtn End Sub
VB Code:
Private Sub Form_Load() MsgBox numberOfControlsOnForm(Me) MsgBox numberOfControlsOnForm(frmSomeOtherForm) End Sub Public Function numberOfControlsOnForm(frmName As Form) As Long Dim x As Control, i As Long For Each x In frmName.Controls i = i + 1 Next numberOfControlsOnForm = i End Function