Radio buttons

F

Fred Blair

I am trying to use Radio Buttons to record a student's choice on a multiple
choice test. I am using the MouseClick event to then put the choice into a
textbox. This is just to learn about radio buttons. After I get this
figured out then the choices will go into an array to save until the test is
completed for scoring.

My code is below, but nothing appears in the textbox when I click on a radio
button.

Advice please,

Fred

*******************Code below**********************

OPrivate Sub Form1_MouseClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick

If RadioButton1.Checked = True Then

TextBox1.Text = "A"

ElseIf RadioButton2.Checked = True Then

TextBox1.Text = "B"

ElseIf RadioButton3.Checked = True Then

TextBox1.Text = "C"

ElseIf RadioButton4.Checked = True Then

TextBox1.Text = "D"

End If

End Sub
 
K

kimiraikkonen

I am trying to use Radio Buttons to  record a student's choice on a multiple
choice test.  I am using the MouseClick event to then put the choice into a
textbox.  This is just to learn about radio buttons. After I get this
figured out then the choices will go into an array to save until the testis
completed for scoring.

My code is below, but nothing appears in the textbox when I click on a radio
button.

Advice please,

Fred

*******************Code below**********************

OPrivate Sub Form1_MouseClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick

If RadioButton1.Checked = True Then

TextBox1.Text = "A"

ElseIf RadioButton2.Checked = True Then

TextBox1.Text = "B"

ElseIf RadioButton3.Checked = True Then

TextBox1.Text = "C"

ElseIf RadioButton4.Checked = True Then

TextBox1.Text = "D"

End If

End Sub

Hi,
Me.Click is fired when you clicked somewhere on your form except your
radio buttons, to fire radio button's checkedChanged event, i'm afraid
you need to create seperate events subs for each radio button as
follows:

'------------------------------
Public Class Form1

Private Sub RB1_CC(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles RadioButton1.CheckedChanged

If RadioButton1.Checked = True Then
TextBox1.Text = "A"
End If
End Sub

Private Sub RB2_CC(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles RadioButton2.CheckedChanged
If RadioButton2.Checked = True Then
TextBox1.Text = "B"
End If
End Sub

Private Sub RB3_CC(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles RadioButton3.CheckedChanged
If RadioButton3.Checked = True Then
TextBox1.Text = "C"
End If
End Sub

Private Sub RB4_CC(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles RadioButton4.CheckedChanged
If RadioButton4.Checked = True Then
TextBox1.Text = "D"
End If
End Sub
'-------------------------------


End Class

Hope this helps,

Onur Güzel
 
J

Jack Jackson

Hi,
Me.Click is fired when you clicked somewhere on your form except your
radio buttons, to fire radio button's checkedChanged event, i'm afraid
you need to create seperate events subs for each radio button as
follows:

'------------------------------
Public Class Form1

Private Sub RB1_CC(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles RadioButton1.CheckedChanged

If RadioButton1.Checked = True Then
TextBox1.Text = "A"
End If
End Sub

Private Sub RB2_CC(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles RadioButton2.CheckedChanged
If RadioButton2.Checked = True Then
TextBox1.Text = "B"
End If
End Sub

I would use the same method for all button click events, and examine
the Sender parameter to see which one was clicked.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top