0

Hello, I wanted to know whether its possible in VB.Net to use a string as an object name.
Lemme describe my problem. I have four radio buttons - p1,p2,p3,p4. Now i want to check whether these buttons are selected or not, for this thing would have to use for if conditions.
I want to know if its possible to use a loop and use "p" + i as the button name. This is possible in flash action script but I dont know whether its possible in VB.Net.

4
Contributors
3
Replies
4
Views
4 Years
Discussion Span
Last Post by adam_k
0

Hi, you could use a code like this, it will return the name of the button you click on.

Private Sub RadioButton1_MouseClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles p1.MouseClick, p2.MouseClick, p3.MouseClick, p4.MouseClick
        Dim str As String = ""
        Dim text As RadioButton = sender
        str = text.Name
        Label1.Text = str
    End Sub
0

If you put the RadioButtons in a container like a GroupBox you can do

For Each rb As RadioButton In GroupBox1.Controls.OfType(Of RadioButton)()
    Debug.WriteLine(rb.Name & " " & rb.Checked)
Next
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.