Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Jul 16, 1998

Control Arrays are Collections

Most VB4 programmers know they can access a form's control collection using a For Each loop. Many, however, are not aware that individual control arrays are actually collections. This knowledge can be helpful when checking the properties of several controls, especially when new controls are loaded at run time. You might wish to create a form in which all text boxes must be filled out. Instead of assigning a unique name to each text box, create a control array with each text box named txtFields. You can use this name as you use the name of any collection in a For Each loop:

 Dim v
	For Each v In txtFields
		If v.Text = "" Then
			MsgBox "All fields must be " & _
				"filled out.", vbExclamation + _
				vbOKOnly
			Exit Sub
		End If
	Next

Because txtFields is a collection, you can also determine how many text boxes are in the array by checking the value of txtFields.Count. For more information, see Karl E. Peterson's Q&A column, "The Keys to Your Controls" [VBPJ August 1997].

Daniel Buskirk
 
Comment and Contribute

 

 

 

 

 


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

 

 

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