CheckBox

C

Carlo

Hi
I have checkboxes names chk1, chk2, chk3 etc
I need to count the number of checkboxes that have been ticked.
I was hoping to loop through the checkboxes by using:
for i = 1 to 40
if chk(i).checked = true then
total += 1
end
next

But the problem it seems is with chk(i). How do I loop through a
control name using a variable such as i?

Thanks
carlob1
 
K

Ken Tucker [MVP]

Hi,

Debug.WriteLine(TotalChecked(Me))



Private Function TotalChecked(ByVal ctrl As Control) As Integer

Dim intTotal As Integer

For Each c As Control In ctrl.Controls

If TypeOf c Is CheckBox Then

intTotal += 1

Else

intTotal += TotalChecked(c)

End If

Next

Return intTotal

End Function



Ken
 
A

Ayaz Ahmed

Hello,

Dim BillsItemChecked As Integer

For Each itm In ListViewPostBills.ListItems


If itm.Checked = True Then


BillsItemChecked = BillsItemChecked + 1

End If
Next itm


Thanks,


Warm Regards,

Ayaz Ahmed
Software Engineer & Web Developer
Creative Chaos (Pvt.) Ltd.
"Managing Your Digital Risk"
http://www.csquareonline.com
Karachi, Pakistan
Mobile +92 300 2280950
Office +92 21 455 2414
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top