How to Create an Option Box in Visual Basic
When they want to create an interface that extracts information from the user, Visual Basic is a common solution for programmers. Visual Basic makes it easy to a group of option boxes, the best way to handle a situation where you want to present the user with a finite number of possible options. With a group of option boxes, users can only choose one, and their choice causes all other option boxes in the same group to be automatically deactivated. Once a user has selected an option box, your code can take action depending on which box in the group was selected.
Instructions
-
Create the Group of Option Boxes
-
1
Open the "Toolbox" palette. Hover the mouse over each tool in until you find the one called "Frame" (its name will pop up on the side as a yellow tag). Double-click the "Frame" tool once you've found it.
-
2
Examine the frame that has been created on your form. Notice the small squares around its perimeter, which are called resizing handles. Drag on any of these to stretch or shrink the frame's size (it will need to be big enough to hold all the option boxes you'll be inserting). Drag the frame from anywhere in its interior to move it to the desired position.
-
-
3
Click on the frame, so that it will be activated.
-
4
Find and click on the "OptionButton" tool just as you did for the "Frame" tool. Then draw a box inside your form representing the size of the desired option box, taking care to make sure the box remains within the bounds of the frame you drew earlier.
-
5
Continue to draw as many option boxes as you need to represent all possible choices to the user. Make sure all the option boxes are within the bounds of the frame you just created.
Name the Group of Option Boxes
-
6
Select the frame by clicking on it once, and scroll through the properties window until you reach the "Name" property. The properties window has two columns, one for the name of each property, and one for the value that the property is set to. Click in the column next to "Name," and type in any single alphanumeric word that you can use to identify the frame in later code.
-
7
Follow standard naming conventions. Frame names should begin with "fra" and then be followed by a capitalized short word that describes the frame's function. If the frame will be linked to a database, consider naming it "fra" plus the name of the field it's to be linked to.
-
8
Select, in turn, each option box within the frame, and as you did for the frame, set each of their "Name" properties to any single alphanumeric word that you can use to identify the option button in later code. Repeat this step for each option boxes in the frame.
-
9
Begin the option box names with "opt" and follow this with a capitalized short word that describes the option box's function. If the option box will be linked to a database, consider naming it "opt" plus the name of the field it's to be linked to.
-
1
Tips & Warnings
An option box by itself isn't much use since it can only be turned on or off. For situations where you only want to present two options like this, it's better to use a check box.
Make sure that as you place option boxes, each of them lands within the frame. Otherwise the box in question won't be considered part of the same group as the others and won't function with them.