Chapter 5. Working with Data Structures

In the previous chapters, you worked with simple data types, namely Integer and String variables. Although these data types are useful in their own rights, more complex programs call for working with data structures; that is, groups of data elements that are organized in a single unit. In this chapter, you learn about the various data structures available in Visual Basic 2008. You also will see some ways in which you can work with complex sets of data. Finally, you learn how you can build powerful collection classes for working with, maintaining, and manipulating lists of complex data.

In this chapter, you learn about:

  • Arrays

  • Enumerations

  • Constants

  • Structures

Understanding Arrays

A fairly common requirement in writing software is the need to hold lists of similar or related data. You can provide this functionality by using an array. Arrays are just lists of data that have a single data type. For example, you might want to store a list of your friends' ages in an integer array or their names in a string array.

In this section, you take a look at how to define, populate, and use arrays in your applications.

Defining and Using Arrays

When you define an array, you're actually creating a variable that has more than one dimension. For example, if you define a variable as a string you can only hold a single string value in it:

Dim strName As String

However, with an array you create a kind of multiplier effect with a variable, so you can hold more than one value ...

Get Beginning Microsoft® Visual Basic® 2008 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.