How to Create an Option Box in Visual Basic

By eHow Internet Editor

Rate: (5 Ratings)

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

Difficulty: Easy

Create the Group of Option Boxes

Step1
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.
Step2
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.
Step3
Click on the frame, so that it will be activated.
Step4
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.
Step5
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

Step1
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.
Step2
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.
Step3
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.
Step4
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.

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.

Post a Comment

POST A COMMENT

Request a New How-To Article

Looking for more How To information? Chances are there’s an eHow member who knows how to do what you’re looking to do. Submit an article request now!

eHow Article: How to Create an Option Box in Visual Basic

eHow Internet Editor

eHow Internet Editor

Category: Internet

Articles: See my other articles

Related Ads

Internet

Veesites
Meet Virginia DeBolt eHow’s Internet Expert.