Arrays Are Zero Based

Visual Basic 2005 arrays cannot have a lower bound other than zero (0). You cannot set the lower bound to 1, as you can when you use VBA. If you want to initialize the array at the time you declare it, you can place curly brackets ({ }) around all the elements you want to add. You'll notice later in Listing 4.12 that to display the first element of the array (apples), you must reference the element 0.

Even though arrays and collections are zero-based in managed code, keep in mind that when you write code against the Office object models, many of the collections are 1-based instead of 0-based. For example, if you tried to access the first bookmark in the Bookmarks collection using the following code example, a run-time error would occur:


0 0

Post a comment