Combo Box Items Counter

Enter your search terms Submit search form

 


 

 

A few hours ago I came across a VB question in Yahoo! Answers section that is related to counting items in a combo box, it goes like this " I have two combo boxes.
1st combo has 'Pendrives, Games & Mobiles' values 2nd combo repeats these three values many times. i want to count particular values (Eg: how many times pendrive repeats)  How can i count how many times these three values repeats.
Help me."

 

I tried out a program in  for this problem and it works!
Basically you need to use a For.....Next loop and If....Then.... Elseif statements to count the items in the Combo Box. You can specify each item using Combo1.List(index). I also created an Input Box for the user to enter the items. I am only using two items here, you can easily add more items yourself.

 

Here is the program:

Private Sub Command1_Click()
Dim item1, item2 As Integer
Item = InputBox("Enter an item")
Combo1.AddItem Item
End Sub
 

Private Sub Command2_Click()
Dim count, i, item1, item2 As Integer
count = Combo1.ListCount
For i = 0 To count
Combo1.Text = Combo1.List(i)
If Combo1.Text = "pendrive" Then
item1 = item1 + 1
ElseIf Combo1.Text = "games" Then
item2 = item2 + 1
End If
Next
Label1.Caption = item1
Label2.Caption = item2

End Sub

 

 

 

 

 

 

 [Back to VBToday]