15.04.2018 Views

programming-for-dummies

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

312<br />

Using Structures<br />

multiple variables within another variable. So if you had three variables —<br />

FirstName, LastName, and Age — you could store them all within a structure,<br />

such as<br />

Structure Person<br />

Dim FirstName as String<br />

Dim LastName as String<br />

Dim Age as Integer<br />

End Structure<br />

A structure is a user-defined data type. You can’t use a structure until you<br />

declare a variable to represent that structure like this:<br />

Dim Employees as Person<br />

The preceding code creates an Employees variable that actually contains<br />

the FirstName, LastName, and Age variables, as shown in Figure 1-1.<br />

FirstName:<br />

Figure 1-1:<br />

A structure<br />

can contain<br />

multiple<br />

variables.<br />

LastName:<br />

Age:<br />

Storing data in separate<br />

variables means keeping<br />

track of each variable<br />

FirstName:<br />

LastName:<br />

Age:<br />

A structure groups<br />

separate variables to<br />

help you keep related<br />

data together.<br />

Storing data<br />

To store data in a structure, you must<br />

1. Identify the variable that represents that structure.<br />

2. Identify the specific variable inside the structure to use.<br />

So if you want to store the name Joe in the FirstName variable inside the<br />

Employee variable, you could do the following:<br />

Employee.FirstName = “Joe”

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!