Visual Basic.Net Programming

Using Radio Buttons

This program uses a group of Radio Buttons to change the language of a greeting in a text box.

You will need to have 2 command buttons:

cmdQuit
cmdDisplay

A text box
txtGreeting

and 3 Radio Buttons

rdoEnglish
rdoFrench
rdoIndonesian or more if you know other languages

Double click your exit button and add the code me.close

Then double click the display button and enter the code below.

If rdoEnglish.Checked = True Then
txtGreeting.Text = "Good Morning!"
ElseIf rdoFrench.Checked = True Then
txtGreeting.Text = "Bon Jour!"
ElseIf rdoIndonesian.Checked = True Then
txtGreeting.Text = "Apa kabar!"
End If

Note that if you know any other languages you simply add another radio button suitably labeled and add another two lines to the code above (you should be able to work it out!)

Radio Buttons can only have one selected at a time. If you want to have several sets of radio buttons on your form then each group has to be put inside a Groupbox control to separate them.

Check boxes are similar but each check box is independant which means you can have more that one checked.

Challenge: Add two check boxes to your form - one near each of the command buttons. When such that when they are checked (true) the command button should be visible.

Code will be something like

If chkQuit.value = 1 then

cmdQuit.visible = true

else cmdQuit.visible = false

end if