loop through panels

scorpio1179
12-10-2004, 08:20 AM
Hi everyone!

I am trying to loop through the panels and get the text of the radiobutton within the panel.
I did the following and it worked but it is very redundant.
I would do the following but I have to do it 11 times.
thanks so much!!

Heidi.

Dim radio As RadioButton
Dim pan As Panel
Dim hh(11) As String

For Each radio In Panel1.Controls
If radio.Checked Then
hh(0) = radio.Text
End If
Next

For Each radio In Panel2.Controls
If radio.Checked Then
hh(1) = radio.Text
End If
Next

For Each radio In Panel3.Controls
If radio.Checked Then
hh(2) = radio.Text
End If
Next

For Each radio In Panel4.Controls
If radio.Checked Then
hh(3) = radio.Text
End If
Next

For Each radio In Panel5.Controls
If radio.Checked Then
hh(4) = radio.Text
End If
Next

For Each radio In Panel6.Controls
If radio.Checked Then
hh(5) = radio.Text
End If
Next

For Each radio In Panel7.Controls
If radio.Checked Then
hh(6) = radio.Text
End If
Next

wayneph
12-10-2004, 08:25 AM
One option might be to set up a Control Array.

Iceplug's Tutorial (http://www.xtremevbtalk.com/showthread.php?t=174835)

scorpio1179
12-10-2004, 08:44 AM
how do you do a control array?

wayneph
12-10-2004, 10:30 AM
The title of Iceplug's tutorial that I linked to is: Control Array's in .NET

What have you tried from there?

scorpio1179
12-10-2004, 12:55 PM
I'm sorry I did not see the link at first. This was excellent help!!!!
Thank you so much!!!!

I used the following and it worked:

Dim pan(10) As Panel
Dim hh(10) As String
Dim check(10) As Integer
Dim rad As RadioButton
Dim i As Integer

pan(0) = Panel1
pan(1) = Panel2
pan(2) = Panel3
pan(3) = Panel4
pan(4) = Panel5
pan(5) = Panel6
pan(6) = Panel7
pan(7) = Panel8
pan(8) = Panel9
pan(9) = Panel10
pan(10) = Panel11


For i = 0 To 10
For Each rad In pan(i).Controls
If rad.Checked Then
hh(i) = rad.Text 'saves text value of each radio button
check(i) = 1 ' flag to identify that radio button was checked
Exit For ' if one is checked the just exit for loop
Else
check(i) = 0
End If
Next
Next

piggybank1974
12-12-2004, 05:44 AM
hi scorpio1179,

here is a one of my modules, with a little change will do what you want

it searches through all GroupBox, Panels for a TextBox but you can change this to what you want.


Module ModSubsAndFunctions

Public m_BlankControl As Boolean

Public Sub CheckBlankControls(ByVal ctl As Control)
Dim aControl As Control

For Each aControl In ctl.Controls
If TypeOf aControl Is GroupBox Or TypeOf aControl Is Panel Then
CheckBlankControls(aControl)
End If
If TypeOf aControl Is TextBox Then
If aControl.Text = "" Then
aControl.Focus()
m_BlankControl = True
End If
End If
Next

End Sub
End Module


the pig..

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum