|
-
Nov 28th, 2001, 10:37 AM
#1
Thread Starter
Hyperactive Member
I need help with "for each"
I have this code and i would like to reduce it with a for each instruction, is there a way?
Shape1.BackColor = vbRed
Shape1.BorderColor = vbGreen
Shape2.BackColor = vbRed
Shape2.BorderColor = vbGreen
Shape3.BackColor = vbRed
Shape3.BorderColor = vbGreen
Shape4.BackColor = vbRed
Shape4.BorderColor = vbGreen
Shape5.BackColor = vbRed
Shape5.BorderColor = vbGreen
Shape6.BackColor = vbRed
Shape6.BorderColor = vbGreen
Shape7.BackColor = vbRed
Shape7.BorderColor = vbGreen
Shape8.BackColor = vbRed
Shape8.BorderColor = vbGreen
Shape9.BackColor = vbRed
Thanx
-
Nov 28th, 2001, 10:43 AM
#2
Frenzied Member
Try this
VB Code:
dim c as control
for each c in me.controls
if typename(c) = "Shape" then
c.backcolor = vbred
c.bordercolor = vbgreen
end if
next c
-
Nov 28th, 2001, 10:45 AM
#3
Frenzied Member
VB Code:
Dim lctrl As Control
For Each lctrl In Controls
If TypeOf lctrl Is Shape Then
lctrl.backcolor = vbRed
lctrl.forecolor = vbGreen
End If
Next
-
Nov 28th, 2001, 10:45 AM
#4
Code:
Dim ctl as control
For each ctl in form1.controls
if typeof ctl is Shape then
.BackColor = vbRed
.BorderColor = vbGreen
End If
Next ctl
You're having problems as it's a control name, there are 2 solutions with this one - the above, looping through all the forms controls, or to put all the shapes in a control array and loop through these shape(i).backcolor etc.
-
Nov 28th, 2001, 10:46 AM
#5
Thread Starter
Hyperactive Member
-
Nov 28th, 2001, 10:48 AM
#6
Damn, well and truly beaten to that one
-
Nov 28th, 2001, 11:19 AM
#7
PowerPoster
Another nice and easy way to do this would be like this:
VB Code:
For i = 1 To 9
Controls("Shape" & i).BackColor = vbRed
Controls("Shape" & i).BorderColor = vbGreen
Next
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|