Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Control Arrays - fairly simple question 1

Status
Not open for further replies.

Cndn

Programmer
Nov 22, 2001
22
0
0
CA
Does anyone know if there is a way to designate an entire control array instead of one particular object in the array?

Ex. How would you make the backcolor of every object in an array blue?

Ex2. How would you make the backcolor of a single button in an array of buttons turn red when clicked?

Ex3. How would you make a single object in an array turn red when the user typed text identical to it's tag in a textbox?
 
For I = 0 To Text1.Ubound
text1(I).BackColor = Rgb(0,0,255)
Next

cmdBtn(whatever).Backcolor = RGB(255,0,0)

Sub Text1_Change(Index As Integer)
If LCase$(text1(Index).Text) = LCase$(text1(Index).Tag) then
text1(Index).BackColor = RGB(255,0,0)
else
text1(Index).BackColor = RGB(255,255,255)
End if
End Sub Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
I have also used code like this

Private Sub cmdBtnArray_Click(Index As Integer)
Dim cmd As CommandButton

For Each cmd In cmdBtnArray()
cmd.Caption = "newCaption"
Next
End Sub

Hope this helps. Anything is possible, the problem is I only have one lifetime.
[cheers]
 
I use the For/Each - it is definitely easier to work with and safer.
If you ever decide to delete one of the objects, then when using the UBound you would need to offset the loop variable with-in the loop when the loop is on the missing index, or, you will need to re-index everything. This can get very messy.

With For/Each, indexes can still be checked with-in the loop if needed.....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top