Using Option Buttons
Let us now develop an application that uses option
buttons. In this application user is
given three subjects and two types of courses to choose from. After selecting
the options if user clicks on Display Amount button then the course fee will be
displayed in a message box.
See figure 3.3, to get an idea about the required user
interface. And following are the steps to create this application.
1.
Start a new project using File -> New Project.
2.
Select Standard
Exe as the type of the project.
3.
Place a Frame control
in the upper-left corner of the form.
4.
Place three options buttons inside the frame. One way
of verifying whether option buttons are inside the frame or not, is by moving
frame. If all option buttons are also moving then it means buttons are inside
the frame.
5.
Place one more frame in the upper-right corner. As we
have to have two different sets of options, we have to use two frames. First
frame contains three subjects and second frame contains two course types.
6.
Place two command buttons at the appropriate location
(see figure 3.3).
7.
Now change the following properties of the controls.
Writing code
Now, let us write code for cmdDisplayAmt command button. When user clicks on this button we
have to calculate the amount to be paid by the student and display that amount
in a message box.
Private Sub
cmddisplayamt_Click()
Dim amount As Integer
' find out the amount
based on the selections made by user
If optoracle.Value
Then
amount = 6000
ElseIf optvb.Value
Then
amount = 5000
Else
amount = 5500
End If
' give a discount of
10% if fulltime is selected
If optft.Value Then
amount = amount *
0.9 ' 10% discount
End If
' display the value
using a message box
MsgBox "Amount to
be paid : " & Str(amount), , "Amount"
End Sub
Private Sub cmdquit_Click()
Unload Me
End Sub
No comments:
Post a Comment