|
-
Nov 24th, 2003, 11:51 AM
#1
frames and foreach..next loop
ok, I have a form that has about 10 frames that are all different background colors so that when I'm editing the program I can see them easily.. when the form loads, I just do a .BackColor change, but I want to try using a For Each Next loop so that I don't have to have 10 lines of code when I could just put a loop that does it for me instead.. I tried it; but I couldn't get it to work, and I've never used For Each loops before in VB, so I don't know how I could get it working. This is what I have so far for it:
VB Code:
Private Sub Form_Load()
'make frame background colors coordinated
For Each Frame In Form
Frame.BackColor = RGB(255, 255, 255)
Next
End Sub
Is this even possible, or am I just running in the wrong direction or something? Also, I know I could easily just put in the extra lines of code.. but I want it to be automated.. because that's cool and stuff.. It's just one of those programmer things.. no reason to really do it; you just do it to make it be awesome.
edit: oh, I forgot to mention.. it gives me a type mismatch error..
Last edited by kows; Nov 24th, 2003 at 11:58 AM.
-
Nov 24th, 2003, 11:58 AM
#2
VB Code:
Dim ctl As Control
For Each ctl In Controls
If TypeOf ctl Is Frame Then
ctl.BackColor = RGB(255, 255, 255)
End If
Next
-
Nov 24th, 2003, 11:59 AM
#3
Addicted Member
I've never used For Each before either, but if you use your frames as arrays, like frame(1), frame(2), etc...
you could just run a for loop to do it
VB Code:
Private Sub Form_load()
For i = 0 to 9
frame(i).Backcolor = RGB(255, 255, 255)
Next i
End Sub
C++/VB6&.NET/QBasic/HTML/PHP/MySQL/SQLServer2k
I'm the guy your little brother looks a lot alike. Tell your mom i said thanks.
naked in vegas
-
Nov 24th, 2003, 12:00 PM
#4
Addicted Member
use marty's.. he's smarter
C++/VB6&.NET/QBasic/HTML/PHP/MySQL/SQLServer2k
I'm the guy your little brother looks a lot alike. Tell your mom i said thanks.
naked in vegas
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
|