Saturday, December 10, 2011

Choice Selection

Choice selection can easily be programmed in Visual Basic, the control involved is the check box. The status of the check box is either checked or unchecked, and the syntax is Checkbox1.Value=VbChecked or Checkbox1.Value=Unchecked. In the following program , I constructed a three-choice selection list. After the user made the selection, a message box will appear to display the list of choices selected. The code is as follow:  Private Sub Command1_Click()
If Check1.Value = vbChecked And Check2.Value = vbChecked And Check3.Value = vbChecked Then
MsgBox ("You like Reading, Computer and Sports")
ElseIf Check1.Value = vbChecked And Check2.Value = vbChecked And Check3.Value = vbUnchecked Then
MsgBox ("You like Reading and Computer")
ElseIf Check1.Value = vbChecked And Check2.Value = vbUnchecked And Check3.Value = vbChecked Then
MsgBox ("You like Reading and Sports")
ElseIf Check1.Value = vbUnchecked And Check2.Value = vbChecked And Check3.Value = vbChecked Then
MsgBox ("You like Computer and Sports")
ElseIf Check1.Value = vbChecked And Check2.Value = vbUnchecked And Check3.Value = vbChecked Then
MsgBox ("You like Reading and Sports")
ElseIf Check1.Value = vbChecked And Check2.Value = vbUnchecked And Check3.Value = vbUnchecked Then
MsgBox ("You like Reading only ")
ElseIf Check1.Value = vbUnchecked And Check2.Value = vbChecked And Check3.Value = vbUnchecked Then
MsgBox ("You like computer only")
ElseIf Check1.Value = vbUnchecked And Check2.Value = vbUnchecked And Check3.Value = vbChecked Then
MsgBox ("You like Sports only")
Else
MsgBox ("You have no hobby")
End If
End Sub

No comments: