Radio Buttons

What are we doing today?
  1. Radio Buttons
  2. Math Expressions
  3. No Brainer
  4. Questions
  5. Computer Assignments

Radio Buttons and Group Boxes

Radio buttons are little circles that you can click on. Only one radio button can be active at a time. Occasionally, you will hear Radio Buttons called option buttons. 

Radio buttons are placed in a GroupBox. The GroupBox causes any radio button to be turned off when another is turned on. This way, only one radio button is active at a time.

Place the GroupBox on the form first by double click on the button in your toolbox and clicking and dragging its size directly onto your form.

To place the radio buttons inside the frame, click once on the radio button and click inside the GroupBox holding the mouse button down, and dragging the mouse to the size that you would like your radio button to be.

The prefix for a GroupBox is grp

The prefix for a radio button is rad

Top of page

Math Expressions

The computer will calculate Mathematical expressions. The order of operations is the same as in Math. Here is a list of some of the mathematical expressions:
+ Plus
- Minus
* Times
/ Divide
\ Integer Division. This chops off the decimals of the answer.
^ Exponents
To Display the answer to the mathematical expression, you do not include the quotation marks. For example:
lblAnswer.Text = "5 + 5"' will display 5 + 5
lblAnswer.Text = 5 + 5' will display 10
Top of page

Concatenation Character

Concatenation is a fancy name for saying you are displaying more than one thing to a label. It means you are combining strings. The character you use is called the concatenation character (& or shift+7). Here is an example of how it is used:
	lblArea.Text = "5+5 = " & 5 + 5
This would display as follows:
	5+5 = 10


Comments are code that does not get compiled by the computer. They are notes to the programmer that visual basic will ignore. They are used for the following reasons: To write a comment, you simple put a single quotation before the line of code you wish to comment.
    Private Sub btnClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClose.Click
        'This line of code will end the program.
    End Sub

In the example above the line that says "This line of code will end the program" is a comment. The compiler will not read it. It is simple some notes for the programmer.
Top of page

No Brainer

Write a Rectangle Area and Perimeter Program. The program will display the area and perimeter for a rectangle length 5 and width 3. Set up a Visual Basic Project with the following objects and properties.
FormName: frmRectangle
Text: Rectangle Area and Perimeter
LabelName: lblRectangle
Text: What is the area and parimeter of a rectangle with the length of 14 feet and width 19 feet?
LabelName: lblAnswer
Text: blank
GroupBoxName: grpRectangle
Text: Select One
RadioButtonName: radArea
Text: &Area
RadioButtonName: radPerimeter
Text: &Perimeter
ButtonName: btnClose
Text: &Close
Your form should look similar to this:
'Programmer:    Your Name
'Program:       Rectangle Area and Perimeter
'Description:   Finds the area and perimeter of a rectangle
Public Class frmRectangle
    Inherits System.Windows.Forms.Form

    Private Sub radArea_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radArea.CheckedChanged
        lblAnswer.Text = "Area:" & vbCrLf & "The Area is " & _
            (14 * 19) & " square feet"
    End Sub

    Private Sub radPermiter_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radPermiter.CheckedChanged
        lblAnswer.Text = "Perimeter:" & vbCrLf & "The perimeter is " & _
                2 * (14 + 19) & " feet long"
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
    End Sub
End Class
Top of page


  1. What is the three letter prefix for a group box?
  2. What it the purpose of the group box?
  3. What is the prefix for a RadioButton?
  4. Why is it important to place radio buttons inside a GroupBox?
  5. What is the character used to divide and cut off any decimals?
  6. What is the character used to display exponents?
  7. Write the statement to display 2 squared in a label named lblSquared.
  8. What is the concatenation character?
  9. Write a statement to display a 6-2=4 where the computer figures out the answer.
Top of page

Computer Assignments

Program 1 (C8P1)

Write a Calculations application that displays the result for the calculation after clicking the button. Have the computer calculate the answer to the equation. Your program should look similar to this:

Program 2 (C8P2)

Write a vacation program that allows the user to select from different vacations. For each selection, you should include a picture that you find from the Web, and a brief description about the place. The code to import a picture into a picturebox is as follows:
	PictureBoxName.Image = Image.FromFile("picturename")
Replace PictureBoxName with the name of your own picturebox and picturename with the name of your picture including the three letter file extension (jpg, gif, tif, bmp). Make sure to save your picture in the bin directory of your project folder. Your program should look similar to this:

Program 3 (C8P3)

Write a Speed Limit Program that will tell the user how fast they are going in Kilometers and Miles. Every 1 mile is 1.6 Kilometers. When Kilimeters is selected, it will display the result of 50 * 1.6. Have the computer calculate the answer. Your program should look similar to this:

Back to Top