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.

Using Structures 313<br />

If you wanted to store the name Smith in the LastName variable and the<br />

number 24 in the Age variable, inside the Employee variable, you could do<br />

the following:<br />

Employee.FirstName = “Joe”<br />

Employee.Age = “24”<br />

Retrieving data<br />

After you store data in a structure, you can always retrieve it again. Just<br />

identify<br />

✦ The variable that represents that structure<br />

✦ The actual variable name that holds the data<br />

Suppose you defined a structure, as follows:<br />

Structure Workers<br />

Dim Name as String<br />

Dim ID as Integer<br />

Dim Salary as Single<br />

End Structure<br />

Be<strong>for</strong>e you can store any data in a structure, you must first declare a variable<br />

to represent that structure like this:<br />

Book III<br />

Chapter 1<br />

Dim Employees as Workers<br />

Now you can store and retrieve data from a structure, as follows:<br />

‘ This stores a name in the Employees structure<br />

Employees.Name = “Jessie Balkins”<br />

Structures<br />

and Arrays<br />

To retrieve data from this structure, identify the variable name that represents<br />

that structure and the variable that holds the data like this:<br />

Print Employees.Name<br />

This would retrieve the data in the Name variable, stored in the Employees<br />

variable structure, and print Jessie Balkins on-screen.<br />

Structures are just a way to cram multiple variables into a single variable. A<br />

structure can hold only one group of related data. To make structures more<br />

useful, programmers typically use structures with another data structure or<br />

an array.

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

Saved successfully!

Ooh no, something went wrong!