Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Jun 18, 1999



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Limit Selected Check Boxes With Collection Logic

Use the Count property to determine exactly how many controls are loaded. You can also use the For Each loop to perform code on each control. For instance, if you have a control array of check boxes and you don't want more than three checked, use this code:

Private Sub Check1_Click(Index As Integer)
	Dim chk As CheckBox
	Dim lCnt As Long
	Const cMAX = 3

	For Each chk In Check1
		If chk.Value = vbChecked Then
			lCnt = lCnt + 1
			If lCnt > cMAX Then
				Check1(Index).Value = vbUnchecked
				MsgBox "Too many checked!"
				Exit For
			End If
		End If

	Next chk

End Sub
Joe Karbowski
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date