Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (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 by starcraft
Posted


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

.nerd
  • *Experts*
Posted

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

Posted (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 by starcraft

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...