Ch. 7 Programming Activity #1:

1. Make a combo box and name it cboNames.
2. Set the Style property as dropdown combo.
3. Add your name to the List property.
4. Type Control + Enter in the List property and add the item "John Doe".
5. Set the Text property as "Student Names".
6. Resize the combo box so the whole Text property is displayed.
7. Create a command button and a label.
8. Make the number of items in the combo box appear in the label when the command button is clicked.
9. Execute your program.
10. Create another command button that uses the AddItem method to add the name "Santa Claus" to the combo box when it is clicked.
11. Execute your program and click the second command button. Then, click the first command button to see how many items are now in the combo box.
12. Add a third command button that uses a For/Next loop to change all of the items in the combo box to "Groucho Marx" one at a time. (Hint: Use the List property of the combo box - cboNames.List(j) = "Groucho Marx"     where j is your loop variable. Be careful to start your loop at 0 and to choose the correct terminating value.
13. Execute your program, click the first command button, then the second, and then the third command button. Then, click the dropdown triangle to see "Groucho Marx" listed three times.

 

Solution:

Option Explicit

Private Sub Command1_Click()
    Label1 = cboNames.ListCount
End Sub

Private Sub Command2_Click()
    cboNames.AddItem ("Santa Claus")
End Sub

Private Sub Command3_Click()
    Dim j As Integer

    For j = 0 To cboNames.ListCount - 1
        cboNames.List(j) = "Groucho Marx"
    Next j

End Sub