TopIndex Property Example

This example fills a ListBox control with names of screen fonts and then scrolls through the ListBox when you click the form. To try this example, paste the code into the Declarations section of a form that contains a ListBox control, and then press F5 and click the form.

Private Sub Form_Load ()
   Dim I   ' Declare variable.
   For I = 0 To Screen.FontCount -1   ' Fill list box with
      List1.AddItem Screen.Fonts(I)   ' screen font names.
   Next I
End Sub

Private Sub Form_Click ()
   Dim X   ' Declare variable.
   X = List1.TopIndex   ' Get current index.
   List1.TopIndex = List1.TopIndex + 5   ' Reset topmost item.
   If List1.TopIndex = X Then List1.TopIndex = 0
End Sub