5. Design a form in VB with two Listboxes. Set the style property of both to 0 and 2 (Multiselect) respectively. One with the left arrow and the one with the right arrow. On pressing the left arrow the selected item from List Box 1 should be transferred to List Box 2 (only if it does exist in List Box 2). If the right arrow is pressed, the selected item (multiple selection are not in ListBox1 should be) transferred to List box 1. Add items and remove items buttons for each list. Duplicate item should not be added


Private Sub cmdAddLeft_Click()
Item = InputBox(“Enter Item: “, “Left List”)
For I = 0 To lstLeft.ListCount – 1
If lstLeft.List(I) = Item Then
MsgBox “Record Is Already Present In The List.”, vbOKOnly, “Result”
Exit Sub
End If
Next
lstLeft.AddItem Item
End Sub

Private Sub cmdAddRight_Click()
Item = InputBox(“Enter Item: “, “Right List”)
For I = 0 To lstRight.ListCount – 1
If lstRight.List(I) = Item Then
MsgBox “Record Is Already Present In The List.”, vbOKOnly, “Result”
Exit Sub
End If
Next
lstRight.AddItem Item
End Sub

Private Sub cmdLeft_Click()
For I = 0 To lstRight.ListCount – 1
If lstRight.Selected(I) = True Then
Flag = 0
For J = 0 To lstLeft.ListCount – 1
If lstLeft.List(J) = lstRight.List(I) Then
MsgBox “Record Is Already Present In The List.”, vbOKOnly, “Result”

Flag = 1
Exit For
End If
Next
If Flag = 0 Then
lstLeft.AddItem lstRight.List(I)
End If
End If
Next
End Sub

Private Sub cmdRemoveLeft_Click()
lstLeft.RemoveItem lstLeft.ListIndex
End Sub

Private Sub cmdRemoveRight_Click()
For I = lstRight.ListCount – 1 To 0 Step -1
If lstRight.Selected(I) = True Then
lstRight.RemoveItem I
End If
Next
End Sub

Private Sub cmdRight_Click()
For I = 0 To lstRight.ListCount – 1
If lstRight.List(I) = lstLeft.Text Then
MsgBox “Record Is Already Present In The List.”, vbInformation, “Result”

Exit Sub
End If
Next
lstRight.AddItem lstLeft.Text
End Sub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s