473,569 Members | 2,729 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Radio buttons



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_MouseClic k(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles Me.MouseClick

If RadioButton1.Ch ecked = True Then

TextBox1.Text = "A"

ElseIf RadioButton2.Ch ecked = True Then

TextBox1.Text = "B"

ElseIf RadioButton3.Ch ecked = True Then

TextBox1.Text = "C"

ElseIf RadioButton4.Ch ecked = True Then

TextBox1.Text = "D"

End If

End Sub
Oct 15 '08 #1
3 2446
On Oct 15, 7:40*pm, "Fred Blair" <passp...@thetr avelintexans.co m>
wrote:
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_MouseClic k(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles Me.MouseClick

If RadioButton1.Ch ecked = True Then

TextBox1.Text = "A"

ElseIf RadioButton2.Ch ecked = True Then

TextBox1.Text = "B"

ElseIf RadioButton3.Ch ecked = True Then

TextBox1.Text = "C"

ElseIf RadioButton4.Ch ecked = 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.EventArg s) _
Handles RadioButton1.Ch eckedChanged

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

Private Sub RB2_CC(ByVal sender As System.Object, _
ByVal e As System.EventArg s) _
Handles RadioButton2.Ch eckedChanged
If RadioButton2.Ch ecked = True Then
TextBox1.Text = "B"
End If
End Sub

Private Sub RB3_CC(ByVal sender As System.Object, _
ByVal e As System.EventArg s) _
Handles RadioButton3.Ch eckedChanged
If RadioButton3.Ch ecked = True Then
TextBox1.Text = "C"
End If
End Sub

Private Sub RB4_CC(ByVal sender As System.Object, _
ByVal e As System.EventArg s) _
Handles RadioButton4.Ch eckedChanged
If RadioButton4.Ch ecked = True Then
TextBox1.Text = "D"
End If
End Sub
'-------------------------------
End Class

Hope this helps,

Onur Güzel

Oct 15 '08 #2
On Wed, 15 Oct 2008 09:56:48 -0700 (PDT), kimiraikkonen
<ki************ *@gmail.comwrot e:
>On Oct 15, 7:40*pm, "Fred Blair" <passp...@thetr avelintexans.co m>
wrote:
>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_MouseClic k(ByVal sender As Object, ByVal e As
System.Windows .Forms.MouseEve ntArgs) Handles Me.MouseClick

If RadioButton1.Ch ecked = True Then

TextBox1.Tex t = "A"

ElseIf RadioButton2.Ch ecked = True Then

TextBox1.Tex t = "B"

ElseIf RadioButton3.Ch ecked = True Then

TextBox1.Tex t = "C"

ElseIf RadioButton4.Ch ecked = True Then

TextBox1.Tex t = "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.EventArg s) _
Handles RadioButton1.Ch eckedChanged

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

Private Sub RB2_CC(ByVal sender As System.Object, _
ByVal e As System.EventArg s) _
Handles RadioButton2.Ch eckedChanged
If RadioButton2.Ch ecked = 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.
Oct 15 '08 #3
Duncan Mackenzie created a control which might be of interest. Find it here
http://msdn.microsoft.com/en-us/magazine/cc163959.aspx

For an enhanced version email me for the source.

"Fred Blair" <pa******@thetr avelintexans.co mwrote in message
news:gd******** **@aioe.org...
>

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_MouseClic k(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles Me.MouseClick

If RadioButton1.Ch ecked = True Then

TextBox1.Text = "A"

ElseIf RadioButton2.Ch ecked = True Then

TextBox1.Text = "B"

ElseIf RadioButton3.Ch ecked = True Then

TextBox1.Text = "C"

ElseIf RadioButton4.Ch ecked = True Then

TextBox1.Text = "D"

End If

End Sub


Oct 21 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6135
by: sman | last post by:
Hi, I recently read this article on About.com on how to create required fields for a form: http://javascript.about.com/library/scripts/blformvalidate.htm Everything works great except that there are no instructions on how to make checkboxes and radio buttons required. I've tried adding these to my form, but I'm having no luck. Anyone know...
2
3132
by: Jeff | last post by:
I'm trying to create a dynamic form that can have multiple groups of radio buttons (each group has two buttons) with the same name. Essentially, the form allows a user to enter as many names as they want. If they need to add more, they click an "add name" button and the javascript inserts another row of input boxes. Each row should have...
4
3262
by: Oscar Monteiro | last post by:
I Have to sets of Radio buttons like so: <input type="radio" name=p1 value=1> <input type="radio" name=p1 value=2> <input type="radio" name=p1 value=3> <br> <input type="radio" name=p2 value=1> <input type="radio" name=p2 value=2> <input type="radio" name=p2 value=3> then a text area and a button:
6
3270
by: Craig Keightley | last post by:
I have a page that has n number of radio groups (yes/No) how can i prevent the form being submitted if more than one radio group is not selected? By default all radio groups are unchecked The problem i am facing is that i do not know how many yes/no radio groups will be generated
2
5416
by: Rob | last post by:
Hi all, I've got multiple sets of radio button that are dynamically created in code and populated by a database query. The query returns about 20 recordsets with 3 radio buttons per recordset and I want to be able to retrieve the selected value from each of the sets of radio buttons.The names of each group of radio buttons is set by the...
2
11945
by: James P. | last post by:
Help, I need to display radio buttons on a form. The data is from SQL table: each row in each table is displayed as a radio button. I have multiple SQL tables so I understand I need to put them each in a GroupBox. All the examples I saw from the books or from the web show me how to add static radio buttons at design, or dynamically at...
1
6861
by: kenny8787 | last post by:
Hi, can anyone help here? I have the following code generated from a database, I want to have javascript calculate the costs of the selected items using radio buttons, subtotal the costs and grandtotal the costs ready for the selected items to be inserted back to the database. I did something like this before with Checkboxes, but...
2
5881
by: dpazza | last post by:
Hi, I'm creating a quiz on using a form in VB 2005 express. I have four sets of questions and answers (labels and radio buttons) and I change between which set of questions is currently shown on the form by changing the visible state of the radio buttons and labels utilising back and next buttons. E.g. Next button makes current radio...
4
2507
by: Blasting Cap | last post by:
I have a page that has a number of radio buttons that will be displayed to different access levels of a user who logs in to my website. For instance, if there are a dozen buttons, user1 will see all twelve. User2 would see buttons 1-3,10-12 and NOT any others, and so on. Since there are several buttons on the page (each one would run a...
11
2260
by: Twayne | last post by:
Hi, Newbie to PHP here, no C or other relevant background, so pretty niave w/r to the nuances etc. but I think this is pretty basic. XP Pro, SP2+, PHP 4.4.7, XAMPP Local Apache Server 6.something I think and running as a service, Using NoteTab Pro as an IDE (works well). If you need more, just ask. In one functioning form:
0
7609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7921
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7666
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6278
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.