Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27514

Capture the array number of the selected button in a radiobutton array

$
0
0
I'm fairly new to vb.net. At one time - many years ago I was reasonably competent GFA basic.I have written a basic banking program in vb.net which works well and I am now trying to tidy it up and improve it. At one point in my program I have a set of 5 radiobuttons to make a selection. These were placed on the form and of course there are 5 subs to detect when a selection is made. The result is that I have variable with five possible values which are processed by a 'case select'. Although this works it is a little messy and I would like to do it in far less code. The code below shows an example but I cannot create a sub which will detect and return the array number of the selected radiobutton.
No doubt this is a very simple question, all the same any help would be much appreciated.

Public Class Form1

Dim Choice(4) As RadioButton
Public X As Integer

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Call TheButtons()

End Sub

Private Sub TheButtons()

For I = 0 To 4
Choice(I) = New RadioButton : Choice(I).Parent = Me
Choice(I).Location = New Point(200, 100 + I * 50) : Choice(I).Text = "Button " + I.ToString
Next

End Sub

Private Sub SomeThingOrOther() ' Not clear about what to put here
For I = 0 To 4
If Choice(I).Checked = True Then
X = I ' Captures the array number of the button selected
End If
Next
End Sub
End Class

Viewing all articles
Browse latest Browse all 27514

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>