This article is unfinished. Please consider joining and adding to this article. Read about Page layout beforehand.
- A record is a data structure that contains values of different types, e.g. a record of type Person could consist of a name (string), address (string) and house number (integer)
Programs designed for real companies and organisations rarely just use a set of numeric variables, as many basic programs do. Instead, they deal with data.
Data about books, people, cars, school classes and online profiles drives the Internet, and the computer systems of companies. In order to store and use data, programs called databases are often used. Data in a database is often grouped together into records, made up of related fields of data about a particular item. What about when data is used in a program?
Record structures collate a set of variables into a single item. This item can be copied as a single entity in a program, and each item of data within the record can be used. Just like in a database, a blueprint is used to explain the design of a record.
The image above is an example of a record declaration in Visual Basic 6. A record can have multiple fields of different types.
This image is an example of a record declaration in Visual Basic.net 2013.
Let's look at a block of code that uses the pupil records.
You will see that the record is used as the type for an array. This creates 201 records of the record type pupilrecord. Records use dot notation, so each element of the record is accessed by giving the record's name followed by a dot and the element of the record.
Advantages of records
Records can keep data together in a structured way. When storing lists of data about a person or thing, it makes sure that the data is held together and identified as a single item in the program.
Alternative approaches in languages that do not support records
Some languages do not support records. This includes languages that are class-based, like Python, and languages that are simple, like TrueBASIC.
In Python, a class can act as a record - each class represents a set of fields and the fields are accessed using dot notation.
In TrueBASIC, a record can only be simulated using parallel arrays. This means for each item of information, a separate array is created. All the elements at item 1 of an array will relate to the first record - items at position 2 to the second, and so on.