10.1 Records
Pseudocode syntax for records (above) can be found in the pseudocode guide, as well as examples below.
TYPE Team
DECLARE TeamName : STRING
DECLARE AwayWins : INTEGER
DECLARE HomeWins : INTEGER
DECLARE Draws : INTEGER
DECLARE NextMatch : Date
ENDTYPE
DECLARE MHUnited : Team
MHUnited.TeamName ß “Mill Hill United”
MHUnited.Draws ß 5
Programmatically, only VB.NET supports records in the same way and use as pseudocode. However, a record can be viewed as a cutdown version of a class (A2 content), and as such, all three programming languages support classes and therefore can use a version of a record.
The examples below are taken from the Langfield and Duddel textbook (chapt. 26). They give examples of how to create a record in each language and examples of creating a structure variable or an array/list of records. When you come to do your own, it is common to have arrays/lists of structures.
VB.NET
VB note: Arrays work as in pseudocode. However, if you create a list of a structure type, you need to declare accordingly (example below).
Note, when using lists (instead of arrays), you need to create a single variable of your structure, populate and add this to the list. An example is given below.
Module Module1
Structure Person
Dim FirstName As String
Dim LastName As String
Dim DoB As Date
End Structure
Sub Main()
Dim Teacher As List(Of Person)
Dim tempTeacher As Person ' this variable, of type person is what is added to the list
tempTeacher.FirstName = "Fred")
tempTeacher.LastName = "Smith"
tempTeacher.DoB = #2/5/1981# ' uses US style date format for literal dates
Teacher.Add(tempTeacher)
End Sub
End Module
Python
Python does not support records in the way that pseudocode or VB does. Instead, you must use a class. Classes are discussed in the A2 year and are a different way (paradigm) of programming. However, the text book example demonstrates how they can be carried out.
Java
Java does not support records in the way that pseudocode or VB does. Instead, you must use a class. Classes are discussed in the A2 year and are a different way (paradigm) of programming. However, the text book example demonstrates how they can be carried out.