Upload
kevin-franklin
View
214
Download
0
Embed Size (px)
Citation preview
Indexing
The Idea of Indexing
• Indexing means having several data items organized under a single name where the individual items can be referred to by number
• It’s like having an address where you need a house number as well as a street name
• Indexing is extremely useful for cycling through a group of items using a loop
• We’ve already seen this used in strings
String Structure
• A string in VBA can be variable length and has an internal structure
• Each character in the string has a position number, called an index
• The first character has index 1, etc. So the string “This is a string.” has 17 characters, counting the blanks:
T h i s i s a s t r i n g .1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Indexing in Listboxes
• We’ve been using listboxes as a place to print information on a user form
• But they can also be used in a much more flexible way to store and access information
• The workbook called IndexListBox has examples of how to use these features
• One important fact: indexing in a listbox starts at 0 instead of 1
Some Useful Properties
• lstName.Listcount is the number of items in list box lstName
• lstName(anIndex) is the item in the listbox lstName with index anIndex
• lstName.ListIndex is the index of the selected item in the listbox
Demo: Index ListBox