See Also Example
Applies To
Combo box, directory list box
Description
Specifies the number of items in the list portion of a control; not available at design time and read-only at run time.
Usage
[form.]control.ListCount
Remarks
ListCount provides specific information for each control:
Combo box and list boxthe number of items in the list.
Directory list boxthe number of subdirectories in the current directory.
Drive list boxthe number of drive connections.
File list boxthe number of files in the current directory that match the Pattern property.
If no item is selected, the ListIndex property value is -1. The first item in the list is ListIndex 0, and ListCount is always one more than the largest ListIndex value.
Data Type
Integer
Help:
AddItem Method
List Property
ListIndex Property
RemoveItem Method
Programmer's Guide:
Chapter 3, "Creating and Using Controls"
The example loads a list of your printer fonts into a combo box, displays the first item in the list, and prints the total number of fonts. Each click of the button changes all items in the list to uppercase or lowercase. To try this example, paste the code into the Declarations section of a form that contains a combo box (Style = 2) and a command button. Then press F5 and click the command button.
Sub Form_Load ()
Dim I ' Declare variable.
AutoRedraw = True ' Set AutoRedraw.
For I = 0 To Printer.FontCount - 1 ' Put font names in list.
Combo1.AddItem Printer.Fonts(I)
Next I
Combo1.ListIndex = 0 ' Set text to first item.
' Print ListCount info on form.
Print "Number of Printer fonts: "; Combo1.ListCount
End Sub
Sub Command1_Click ()
Static UpperCase
Dim I ' Declare variable
For I = 0 To Combo1.ListCount - 1 ' Loop through list.
If UpperCase Then
Combo1.List(I) = UCase(Combo1.List(I))
Else
Combo1.List(I) = LCase(Combo1.List(I))
End If
Next I
UpperCase = Not UpperCase ' Change case.
End Sub