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.

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

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

You are looking for cobj()

 cobj("p" & i)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.