demonstrate one way to use a hash table for just such a use—a computer terms glossary. The program works by first reading in a set of terms and definitions from a text file. This process is coded in the BuildGlossary subroutine. The structure of the text file is: word,definition, with the comma being the delimiter between a word and the definition. Each word in this glossary is a single word, but the glossary could easily work with phrases instead. That’s why a comma is used as the delimiter, rather than a space. Also, this structure allows us to use the word as the key, which is the proper way to build this hash table. Another subroutine, DisplayWords, displays the words in a list box so the user can pick one to get a definition. Since the words are the keys, we can usethe Keys method to return just the words from the hash table. The user can then see which words have definitions. To retrieve a definition, the user simply clicks on a word in the list box. The definition is retrieved using the Item method and is displayed in the text box
demonstrate one way to use a hash table for just such a use—a computer terms glossary. The program works by first reading in a set of terms and definitions from a text file. This process is coded in the BuildGlossary subroutine. The structure of the text file is: word,definition, with the comma being the delimiter between a word and the definition. Each word in this glossary is a single word, but the glossary could easily work with phrases instead. That’s why a comma is used as the delimiter, rather than a space. Also, this structure allows us to use the word as the key, which is the proper way to build this hash table. Another subroutine, DisplayWords, displays the words in a list box so the user can pick one to get a definition. Since the words are the keys, we can usethe Keys method to return just the words from the hash table. The user can then see which words have definitions.
To retrieve a definition, the user simply clicks on a word in the list box. The definition is retrieved using the Item method and is displayed in the text box
Step by step
Solved in 3 steps with 1 images