Choice Selection

Very often when you visit a website, you are presented with a list of choices for you to select. Choice selection can easily be programmed in Visual Basic, the control that we can use 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=vbUnchecked. In the following program , we constructed a three-choice selection list. After the user made the selection, a message box will appear to display the list of selected choices .

The Interface

The Code

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
 

 

 

 

 

 [Back to Sample VB Sample Programs]

Copyright ® 2008 Dr.Liew Voon Kiong . All rights reserved |Contact: admin@vbtutor.net

[Privacy Policy]