Radio Buttons in Groupboxes - Code check

  • Thread starter Thread starter Rich
  • Start date Start date
R

Rich

Hi

I have two radio buttons in a groupbox on a Windows form and have wrote the
code below to find out which button is selected. Can anyone tell me if
there is an easier / better way to code this as it seems a bit long?

Thanks

Rich

Dim rbarray As RadioButton()
Dim strValue As String

rbarray = new RadioButton() {rb1, rb2}

Dim i As Integer

For i = 0 To 1
If rbarray(i).Checked Then
strValue = rbarray(i).Text
End If
Next
 
Hi Rich,

There are a lot of other methods, however your code very short and I think
there i nothing wrong with.

You can also do
\\
for each ctr as mygroupbox.controls
if ctr.Checked Then
strValue = ctr.Text
End If
Next
///
This you can do when there are sure there are only radiobuttons, otherwise
you have to put it in a
\\\
if typeof ctr is radiobutton then
......
end if
///
And than it is again longer

I hope this give some idea's?

Cor
 
Hi

I have two radio buttons in a groupbox on a Windows form and have wrote the
code below to find out which button is selected. Can anyone tell me if
there is an easier / better way to code this as it seems a bit long?

Thanks

Rich

Dim rbarray As RadioButton()
Dim strValue As String

rbarray = new RadioButton() {rb1, rb2}

Dim i As Integer

For i = 0 To 1
If rbarray(i).Checked Then
strValue = rbarray(i).Text
End If
Next

Another point is inside the If, after setting the value, put Exit For.
Since only one radio button can be selected (all the others would bel
cleared) as soon as you find the one that is selected, there is no need to
continue looking:

For i = 0 To 1
If rbarray(i).Checked Then
strValue = rbarray(i).Text
Exit For
End If
Next
 
Back
Top