• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 8. Writing Your Own Visual Basic... > Using Arrays with String Functions

Using Arrays with String Functions

The function that you are about to examine counts the words, but it does more than that. It pieces together a string one word at a time. It uses a type of variable called an array. Arrays intimidate some people, but they are actually quite simple. Instead of filling variables one string at a time, arrays enable you to get a whole batch of strings and reference any of them.

Think of an array as if it were a group of cells in a spreadsheet. If you have information in cells A1 through A3, you have an array of cells. If A1 contained FirstName, A2 contained MiddleName, and A3 contained LastName, then you could reference the contents by clicking the appropriate cell. In much the same way, you could set up an array variable. If the name of the array was Fill, you could declare Fill with the statement Dim Fill(2) as String. The (2) simply tells the procedure to allocate three locations for storing variables. The reason that it is three instead of two is that it is zero based. In effect, you are reserving three blocks of memory for the three elements of the array. Fill(0) is a totally different variable from Fill(1). Table 8.1 illustrates the way array variables are stored.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint