VB2019 VB2017 VB2015 VB2013 VB2012 VB2010 VB2008 VB6 VB Sample Codes 中文VB About Us

Choice Selection



Very often when we visit a website, we are presented with a list of choices for us to select. Choice selection can easily be programmed in Visual Basic using 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 , we construct a three-choice selection list. After making a selection, a message box displaying the list of selected choices will appear .

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



Copyright©2008 Dr.Liew Voon Kiong. All rights reserved |Contact|Privacy Policy