starcraft Posted July 15, 2003 Posted July 15, 2003 (edited) i am trying to set a value to ALL label, buttons, text, exc. but the only 2 ways i know of dont work; Way 1: Dim lbl As Label For Each lbl In Me.Controls lbl.BackColor = Color.Black Next [/url] Way 2:Dim button As button For Each button In me.controls button.Visible = False Next but both ways get me errors. i am dealing with lots of textboxes, LOTS of buttons/ lots of labels. Whats a better way to do it? PS---- My program with the code Dim rand As New Random() 'set the variable rand.Next(1, 100)'pick the number TextBox1.Text = (rand.Next)' display the number makes numbers like "881116234" "560519390" why does it pick such big numbers? PS Extra ----- How do i say that if radiobox1 is click to do this but if radiobox2 is clicked then do that? Edited July 15, 2003 by starcraft Quote
Heiko Posted July 15, 2003 Posted July 15, 2003 Public Sub DoSomething (parent as Control) Dim aCtrl as Control For each aCtrl in parent if TypeOf (aCtrl) is Button Then 'lala end if If TypeOf (aCtrl) is TextBox Then 'lala end if 'now the same for the controls that are placed on aCtrl DoSomething (aCtrl) next aCtrl Plus, if required, for the form the same with a different signature: Public Sub DoSomething (aForm as Form) ... End Sub Quote .nerd
*Experts* mutant Posted July 15, 2003 *Experts* Posted July 15, 2003 PS---- My program with the code Dim rand As New Random() 'set the variable rand.Next(1, 100)'pick the number TextBox1.Text = (rand.Next)' display the number makes numbers like "881116234" "560519390" why does it pick such big numbers? You put one too much rand.Next in there :) Dim rand As New Random() TextBox1.Text = rand.Next(1, 100) YOu first picked the number you wanted but then you created a new number without min and max values. PS Extra ----- How do i say that if radiobox1 is click to do this but if radiobox2 is clicked then do that? If RadioButton1.Checked Then 'do what you want when it is selected ElseIf RadioButton2 Checked Then 'do want you want when it is selected End If Quote
starcraft Posted July 15, 2003 Author Posted July 15, 2003 (edited) thanks guys But when i do all that i get a small error, the sending stuff to lots of things, not the random. When i do that it underlines the For Each aCtrl In parent and says X:\vb\Aim Responce\Form1.vb(793): Expression is of type 'System.Windows.Forms.Control', which is not a collection type. whats up? Edited July 15, 2003 by starcraft Quote
*Experts* Volte Posted July 15, 2003 *Experts* Posted July 15, 2003 Change parent to parent.Controls, which refers to the collection of controls contained within the parent. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.