Home

Records

 

Fundamentals of Records

 

Introduction

A record is one variable or a group of variables treated as one entity. This means that the variables are grouped in one type. Outside the group, the type can be accessed as a whole or each variable can be accessed individually.

 

Creating a Record Type

The primary formula to create a record is:

type RecordName = { Labels }

You start with the type keyword, followed by a name. The name of the record follows the rules of names of the F# language. Unlike a variable, you should start the name with a letter in uppercase. After the name, type = followed by an opening and a closing curly brackets. Inside the brackets, enter the name of each member. The member in a record is also called a label. The labels are separated by semicolons. Each label must use the following formula:

label-name : Data-type

That is, each label must be created with a name and its data type. A record can have just one label. Here is an example:

type Student = { FullName : string }

Otherwise, a record can have as many labels as you want. Here is an example:

type Student = { ID : int; FirstName : string; LastName : string; Gender : char }

If there are many labels or to make the code easier to read, you can list the labels on different lines, or each on its own line. Here is an example:

type Student = {
    ID : int;
    FirstName : string;
    LastName : string;
    Gender : char }

If you use this technique, you can omit the semicolons. Here is an example:

type Student = {
    ID : int
    FirstName : string
    LastName : string
    Gender : char }

You can write the opening curly braket on the next line. If you do this, you must indent it. Here is an example::

type Student =
    {
    ID : int;
    FirstName : string;
    LastName : string;
    Gender : char }

In the same way, if you decide to put the closing curly bracket on its own line, make sure you indent it. Here is an example::

type Student =
    {
    ID : int;
    FirstName : string;
    LastName : string;
    Gender : char
    }

Just like you can create one record in a code file, you can created as many records as you want in the same file.

Creating a Record Object

Before using a record, you should assign a value to each of its labels. You do this by creating a record expression. To create a record expression, use the following formula:

let variable-name = { label-name1 = value1; label-name2 = value2; . . .; label-name_n = value_n }

As always, start with let followed by a name for the variable and assign curly brackets to it. Inside the brackets, enter each label of the record and assign a value to it; separate them with semicolons. Here is an example:

type Student = {
    ID : int
    FirstName : string
    LastName : string
    Gender : char }

let std = { ID = 773946; FirstName = "Amir";
            LastName = "Shalloub"; Gender = 'M' }

Remember that you can write each label on its own line to make the code easier to read, in which case you can omit the semicolons:

type Student = {
    ID : int
    FirstName : string
    LastName : string
    Gender : char }

let std = {
    ID = 773946
    FirstName = "Amir"
    LastName = "Shalloub"
    Gender = 'M' }

Notice that the name of the record is not specified in the declaration, but the compiler must be able to identify or recognize the labels that are being accessed in the curly brackets of the variable. This also means that the record must be created before the variable that initializes it. Still, if you want to specify the type of the object, after the name of the variable, type : followed by the name of the record. Here is an example:

type Student = {
    ID : int
    FirstName : string
    LastName : string
    Gender : char }

let std : Student = { ID = 773946; FirstName = "Amir";
            LastName = "Shalloub"; Gender = 'M' }

Using Different Records in the Same Document

Since the variable doesn't identify the record by name, what if there are two or more records that have the same labels? Consider the following example:

type Student = {
    ID : int
    FirstName : string
    LastName : string
    Gender : char }

type Employee = {
    ID : int
    FirstName : string
    LastName : string
    Gender : char }

let std = {
    ID = 773946
    FirstName = "Amir"
    LastName = "Shalloub"
    Gender = 'M' }

Notice that both the Student and the Employee records have the exact same labels. This situation qualifies as ambiguous (common in functional and logical languages). In this case, when you declare a variable that initializes a record, the variable will use the record that is closest to it, which is the most recently created record. In our case, this would be the Employee record.

If you have different records that have labels that use the same name, when declaring a variable that initializes them, you should qualify one or each label in the curcly brackets of the variable. To do this, type the name of the record, followed by a period, and followed by the name of the label. Then assign the appropriate value to the label. Here are examples:

type Student = {
    ID : int
    FirstName : string
    LastName : string
    Gender : char }

type Employee = {
    ID : int
    FirstName : string
    LastName : string
    Gender : char }

let std = {
    Student.ID = 773946
    Student.FirstName = "Amir"
    Student.LastName = "Shalloub"
    Student.Gender = 'M' }

let contractor = {
    Employee.ID = 50225
    Employee.FirstName = "Hellie"
    Employee.LastName = "Pastore"
    Employee.Gender = 'F' }

A Mutable Record

A mutable record is one whose values can change. To create a mutable record, use the mutable keyword. In the curly brackets, assign a default value to each label. A string can be initialized with "". An integer can be initialized with 0, and so on. Here is an example:

type Customer = {
    AccountNumber   : int
    FirstName       : string
    MI              : char
    LastName        : string
    AccountIsActive : bool }

let mutable cust : Customer = {
    AccountNumber = 0;
    FirstName = ""; MI = ''; LastName = "";
    AccountIsActive = false }

Later on, or at any time, you can change the values of the mutable object by assigning new values or changing the values of its labels. Here is an example:

type Customer = {
    AccountNumber   : int
    FirstName       : string
    MI              : char
    LastName        : string
    AccountIsActive : bool }

let mutable cust : Customer = {
    AccountNumber = 0;
    FirstName = ""; MI = ' '; LastName = "";
    AccountIsActive = false }

cust <- {
    AccountNumber = 952749;
    FirstName = "William"; MI = 'T'; LastName = "Leonardson";
    AccountIsActive = true }

cust <- {
    AccountNumber = 7304813;
    FirstName = "Robert"; MI = ' '; LastName = "Euel";
    AccountIsActive = false }

Creating Various Record Objects

In the same way, you can create as many record objects as you want. Here are examples:

type Employee = {
    EmployeeNumber : string
    HourlySalary   : float }

let empl80223840 = { EmployeeNumber = "8022-3840"; HourlySalary = 24.55 }
let empl58402497 = { EmployeeNumber = "5840-2497"; HourlySalary = 16.25 }
let empl20817008 = { EmployeeNumber = "2081-7008"; HourlySalary = 22.75 }

You can also declare many variables using one let keyword. Here is an example:

type Employee = {
    EmployeeNumber : string
    HourlySalary   : float }

let empl80223840, empl58402497, empl20817008 =
    { EmployeeNumber = "8022-3840"; HourlySalary = 24.55 },
    { EmployeeNumber = "5840-2497"; HourlySalary = 16.25 },
    { EmployeeNumber = "2081-7008"; HourlySalary = 22.75 }
     
 

Introduction to Using a Record

 

Accessing a Record

After initializing a record, one way you can use it consists of presenting its values to the user. To do this, you can use %A in the placeholder of the sprintf() function. Here is an example:

open System
open System.Windows.Forms

type Employee = {
    EmployeeNumber  : int
    FirstName       : string
    LastName        : string
    Title           : string }

let empl = {
    EmployeeNumber = 40685
    FirstName      = "Justine"
    LastName       = "Sandt"
    Title          = "Rent Manager" }

let ceilInnHotel = new Form()
ceilInnHotel.Text   <- "Ceil Inn Hotel"
ceilInnHotel.Width  <- 180
ceilInnHotel.Height <- 105

let lblEmployee = new Label()
lblEmployee.Left   <-  12
lblEmployee.Top    <-  12
lblEmployee.Width  <- 160
lblEmployee.Height <-  60
lblEmployee.Text   <- sprintf "%A" empl

ceilInnHotel.Controls.Add lblEmployee

Application.Run ceilInnHotel

This would produce:

Accessing a Record

Accessing the Labels of a Record

To access a label of a record, type the name of the variable you declared, followed by a period, followed by the label you want. Here are examples:

open System
open System.Windows.Forms

type Employee = {
    EmployeeNumber : string
    HourlySalary   : float }

let empl80223840 = { EmployeeNumber = "8022-3840"; HourlySalary = 24.55 }
let empl58402497 = { EmployeeNumber = "5840-2497"; HourlySalary = 16.25 }
let empl20817008 = { EmployeeNumber = "2081-7008"; HourlySalary = 22.75 }

let exercise : Form = new Form()
exercise.Text   <- "Exercise"
exercise.Width  <- 156
exercise.Height <- 158

let lbxEmployees : ListBox = new ListBox()

lbxEmployees.Left <- 12
lbxEmployees.Top  <- 12

lbxEmployees.Items.Add empl80223840.EmployeeNumber |> ignore
lbxEmployees.Items.Add empl58402497.EmployeeNumber |> ignore
lbxEmployees.Items.Add empl20817008.EmployeeNumber |> ignore

exercise.Controls.Add lbxEmployees

Application.Run exercise

This would produce:

Accessing the Labels of a Record

Remember that, if you are using two or more records that have the same labels, to identify a member, you should qualify it in the curly brackets of the variable. Once you have accessed a label of a record, you can involve it in any appropriate operation. Here are examples:

open System
open System.Windows.Forms

type Employee = {
    EmployeeNumber : string
    FirstName      : string
    LastName       : string
    HourlySalary   : float }

type TimeSheet = {
    TSNumber       : int
    EmployeeNumber : string
    Monday         : float
    Tuesday        : float
    Wednesday      : float
    Thursday       : float
    Friday         : float
    Saturday       : float
    Sunday         : float }

let empl80223840 = { EmployeeNumber = "8022-3840"; FirstName = "Mark";  LastName = "Plant";  HourlySalary = 24.55 }
let empl58402497 = { EmployeeNumber = "5840-2497"; FirstName = "Carol"; LastName = "Mylans"; HourlySalary = 16.25 }
let empl20817008 = { EmployeeNumber = "2081-7008"; FirstName = "Maria"; LastName = "Pappas"; HourlySalary = 22.75 }

let payrollPreparation = new Form(Width = 450, Height = 210, Text = "Payroll Preparation")

let lblEmployeeNumber = new Label(Left = 23, Top = 22, Width = 80, Text = "Employee #:")
payrollPreparation.Controls.Add lblEmployeeNumber

let txtEmployeeNumber = new TextBox(Left = 110, Top =  19, Width = 75, Text = "0000-0000")
let txtEmployeeName   = new TextBox(Left = 191, Top =  19, Width = 170)
payrollPreparation.Controls.AddRange([| txtEmployeeNumber; txtEmployeeName |])

let txtEmployeeNumberLostFocus e =
    if txtEmployeeNumber.Text = empl80223840.EmployeeNumber then
        txtEmployeeName.Text <- empl80223840.LastName + ", " + empl80223840.FirstName
    elif txtEmployeeNumber.Text = empl58402497.EmployeeNumber then
        txtEmployeeName.Text <- empl58402497.LastName + ", " + empl58402497.FirstName
    elif txtEmployeeNumber.Text = empl20817008.EmployeeNumber then
        txtEmployeeName.Text <- empl20817008.LastName + ", " + empl20817008.FirstName
    else
        txtEmployeeName.Text <- ""

txtEmployeeNumber.Leave.Add txtEmployeeNumberLostFocus

let lblMonday    = new Label(Left =  23, Top = 51, Width = 50, Height = 13, Text = "Monday")
let lblTuesday   = new Label(Left =  80, Top = 51, Width = 50, Height = 13, Text = "Tuesday")
let lblWednesday = new Label(Left = 134, Top = 51, Width = 65, Height = 13, Text = "Wednesday")
let lblThursday  = new Label(Left = 198, Top = 51, Width = 55, Height = 13, Text = "Thursday")
let lblFriday    = new Label(Left = 253, Top = 51, Width = 50, Height = 13, Text = "Friday")
let lblSaturday  = new Label(Left = 307, Top = 51, Width = 50, Height = 13, Text = "Saturday")
let lblSunday    = new Label(Left = 365, Top = 51, Width = 50, Height = 13, Text = "Sunday")
payrollPreparation.Controls.AddRange([| lblMonday; lblTuesday; lblWednesday; lblThursday; lblFriday; lblSaturday; lblSunday |])

let txtMonday    = new TextBox(Left =  26, Top = 67, Width = 50, Text = "0.00")
let txtTuesday   = new TextBox(Left =  83, Top = 67, Width = 50, Text = "0.00")
let txtWednesday = new TextBox(Left = 140, Top = 67, Width = 50, Text = "0.00")
let txtThursday  = new TextBox(Left = 197, Top = 67, Width = 50, Text = "0.00")
let txtFriday    = new TextBox(Left = 254, Top = 67, Width = 50, Text = "0.00")
let txtSaturday  = new TextBox(Left = 311, Top = 67, Width = 50, Text = "0.00")
let txtSunday    = new TextBox(Left = 368, Top = 67, Width = 50, Text = "0.00")
payrollPreparation.Controls.AddRange([| txtMonday; txtTuesday; txtWednesday; txtThursday; txtFriday; txtSaturday; txtSunday |])

let btnPrepare = new Button(Left = 26, Top = 97, Width = 393, Height = 35, Text = "Prepare")
payrollPreparation.Controls.Add btnPrepare

let lblTimeWorked = new Label(Left = 111, Top = 147, Width = 85, Text = "Time Worked:")
payrollPreparation.Controls.Add lblTimeWorked

let txtTimeWorked = new TextBox(Left = 198, Top = 144, Width = 75, Text = "0.00")
payrollPreparation.Controls.Add txtTimeWorked

let btnPrepareClick e =
    let mon = float txtMonday.Text
    let tue = float txtTuesday.Text
    let wed = float txtWednesday.Text
    let thu = float txtThursday.Text
    let fri = float txtFriday.Text
    let sat = float txtSaturday.Text
    let sun = float txtSunday.Text

    let ts = { TSNumber = 10001; EmployeeNumber = txtEmployeeNumber.Text;
               Monday = mon; Tuesday = tue; Wednesday = wed; Thursday = thu; Friday = fri; Saturday = sat; Sunday = sun }

    let timeWorked = ts.Monday + ts.Tuesday + ts.Wednesday + ts.Thursday + ts.Friday + ts.Saturday + ts.Sunday

    let strTotalTime      = sprintf "%0.02f" timeWorked
    
    txtTimeWorked.Text        <- strTotalTime

btnPrepare.Click.Add btnPrepareClick

let btnClose = new Button(Left = 284, Top = 143, Text = "Close")
let btnCloseClick e = payrollPreparation.Close()
btnClose.Click.Add btnCloseClick
payrollPreparation.Controls.Add btnClose

do Application.Run payrollPreparation

Here is an example of testing the program:

Accessing the Labels of a Record

Accessing the Labels of a Record

Accessing the Labels of a Record

Copying a Record

After creating an object from a record, you may want to create another object whose some labels use the same values as some labels of the previous objects. In this case, you can copy the similar values. To do this, in the {} of the new object, type the name of the object followed by with, the name of the label whose value you want to change and assign the desired value to it. Here is an example:

open System
open System.Drawing
open System.Windows.Forms

type Apartment = {
    UnitNumber      : string
    Bedrooms        : int
    Bathrooms       : float
    SecurityDeposit : int
    MonthlyRate     : int }

let a508293 = { UnitNumber = "102"; Bedrooms = 1; Bathrooms = 1.00; SecurityDeposit = 500; MonthlyRate =  950 }
let a729397 = { a508293 with UnitNumber = "103" }

let apartmentRental : Form = new Form()
apartmentRental.Width <- 290
apartmentRental.Text <- "Lambda Square Apartments"
apartmentRental.Height <- 105

let lbxApartments = new ListBox()
lbxApartments.Left   <-  12
lbxApartments.Top    <-  12
lbxApartments.Width  <- 260
lbxApartments.Height <-  65
lbxApartments.Items.Add ("Unit #\tBeds\tBaths\tDeposit\tRate/month") |> ignore
lbxApartments.Items.Add ("------------------------------------------------------------------------------------") |> ignore
apartmentRental.Controls.Add lbxApartments

lbxApartments.Items.Add (sprintf "%s\t%i\t%0.02f\t%i\t%i" a508293.UnitNumber a508293.Bedrooms a508293.Bathrooms a508293.SecurityDeposit a508293.MonthlyRate) |> ignore
lbxApartments.Items.Add (sprintf "%s\t%i\t%0.02f\t%i\t%i" a729397.UnitNumber a729397.Bedrooms a729397.Bathrooms a729397.SecurityDeposit a729397.MonthlyRate) |> ignore

do Application.Run apartmentRental

This would produce:

Copying a Record

Notice that the second object gets all its values from the object copied, except for the label whose value was changed. In the same way, you can change the value of any of the labels that are different from the copied object. Here are examples:

open System
open System.Drawing
open System.Windows.Forms

type Apartment = {
    UnitNumber      : string
    Bedrooms        : int
    Bathrooms       : float
    SecurityDeposit : int
    MonthlyRate     : int }

let a399475 = { UnitNumber = "101"; Bedrooms = 2; Bathrooms = 2.00; SecurityDeposit = 650; MonthlyRate = 1150 }
let a508293 = { UnitNumber = "102"; Bedrooms = 1; Bathrooms = 1.00; SecurityDeposit = 500; MonthlyRate =  950 }
let a729397 = { a508293 with UnitNumber = "103" }
let a809387 = { UnitNumber = "104"; Bedrooms = 3; Bathrooms = 2.00; SecurityDeposit = 850; MonthlyRate = 1350 }
let a486360 = { a508293 with UnitNumber = "105"; MonthlyRate =  1050 }
let a273004 = { a399475 with UnitNumber = "106"; Bathrooms = 1.00; MonthlyRate = 1050 }

let apartmentRental : Form = new Form()
apartmentRental.Width <- 290
apartmentRental.Text <- "Lambda Square Apartments"
apartmentRental.Height <- 160

let lbxApartments = new ListBox()
lbxApartments.Left <- 12
lbxApartments.Top <- 12
lbxApartments.Width <- 260
lbxApartments.Height <- 120
lbxApartments.Items.Add ("Unit #\tBeds\tBaths\tDeposit\tRate/month") |> ignore
lbxApartments.Items.Add ("------------------------------------------------------------------------------------") |> ignore
apartmentRental.Controls.Add lbxApartments

lbxApartments.Items.Add (sprintf "%s\t%i\t%0.02f\t%i\t%i" a399475.UnitNumber a399475.Bedrooms a399475.Bathrooms a399475.SecurityDeposit a399475.MonthlyRate) |> ignore
lbxApartments.Items.Add (sprintf "%s\t%i\t%0.02f\t%i\t%i" a508293.UnitNumber a508293.Bedrooms a508293.Bathrooms a508293.SecurityDeposit a508293.MonthlyRate) |> ignore
lbxApartments.Items.Add (sprintf "%s\t%i\t%0.02f\t%i\t%i" a729397.UnitNumber a729397.Bedrooms a729397.Bathrooms a729397.SecurityDeposit a729397.MonthlyRate) |> ignore
lbxApartments.Items.Add (sprintf "%s\t%i\t%0.02f\t%i\t%i" a809387.UnitNumber a809387.Bedrooms a809387.Bathrooms a809387.SecurityDeposit a809387.MonthlyRate) |> ignore
lbxApartments.Items.Add (sprintf "%s\t%i\t%0.02f\t%i\t%i" a486360.UnitNumber a486360.Bedrooms a486360.Bathrooms a486360.SecurityDeposit a486360.MonthlyRate) |> ignore
lbxApartments.Items.Add (sprintf "%s\t%i\t%0.02f\t%i\t%i" a273004.UnitNumber a273004.Bedrooms a273004.Bathrooms a273004.SecurityDeposit a273004.MonthlyRate) |> ignore

do Application.Run apartmentRental

This would produce:

Copying a Record

A Mutable Label

By default, after creating a record object, you cannot change the values of its labels. If you want to create a label whose value can change, you must create it as mutable. Here is an example:

type Apartment = {
    UnitNumber      : string
    Bedrooms        : int
    Bathrooms       : float
    SecurityDeposit : int
    mutable MonthlyRate : int }

Before using it, first create an object based on the record. To change the value of the field, type the name of the object, a period, and the name of the field. Then assign the desired value to it, using the <- operator. Here are examples:

type Apartment = {
    UnitNumber      : string
    Bedrooms        : int
    Bathrooms       : float
    SecurityDeposit : int
    mutable MonthlyRate : int }
 
let a399475 = { UnitNumber = "101"; Bedrooms = 2; Bathrooms = 2.00; SecurityDeposit = 650; MonthlyRate = 1150 }
let a508293 = { UnitNumber = "102"; Bedrooms = 1; Bathrooms = 1.00; SecurityDeposit = 500; MonthlyRate =  950 }

// The monthly rent has changed. The new tenant will get a discount

a399475.MonthlyRate <- 1075
a508293.MonthlyRate <- 1025

A Record as a Record Label

A label of a record can be a record type. When creating the label, make sure you appropriately specify its type. The label is usually a different name from the record but it can be the same name. Here is an example:

type Department = {
    DepartmentCode : string
    DepartmentName : string }

type Employee = {
    EmployeeNumber : string
    FirstName      : string
    LastName       : string
    Department     : Department
    Title          : string }

Before creating values for the new record, you can first create values for the first record and use its variable as the value in the new object. Here is an example:

open System
open System.Windows.Forms

type Department = {
    DepartmentCode : string
    DepartmentName : string }

type Employee = {
    EmployeeNumber : string
    FirstName      : string
    LastName       : string
    Department     : Department
    Title          : string }

let dept = {
    DepartmentCode = "ADMN";
    DepartmentName = "Administration, Admissions, and Students Affairs" }
let staff = {
    EmployeeNumber = "161138"
    FirstName = "Laura"
    LastName = "Fannie"
    Department = dept
    Title = "Dean of Litterary Studies" }

// Form: Convenience Store
let employeeRecord = new Form()
employeeRecord.Width  <- 395
employeeRecord.Height <- 220
employeeRecord.Text <- "Employee Record"

// Label: Employee Number
let lblEmployeeNumber = new Label()
lblEmployeeNumber.Left   <- 21
lblEmployeeNumber.Top    <- 19
lblEmployeeNumber.Width  <- 96
lblEmployeeNumber.Text   <- "Employee #:"
employeeRecord.Controls.Add lblEmployeeNumber

// Text Box: Employee Number
let txtEmployeeNumber = new TextBox()
txtEmployeeNumber.Left  <- 125
txtEmployeeNumber.Top   <-  16
txtEmployeeNumber.Width  <- 60
txtEmployeeNumber.Text  <- staff.EmployeeNumber
employeeRecord.Controls.Add txtEmployeeNumber

// Label: First Name
let lblFirstName = new Label()
lblFirstName.Left   <- 21
lblFirstName.Top    <- 45
lblFirstName.Width  <- 96
lblFirstName.Height <- 13
lblFirstName.Text   <- "First Name:"
employeeRecord.Controls.Add lblFirstName

// Text Box: First Name
let txtFirstName = new TextBox()
txtFirstName.Left  <- 125
txtFirstName.Top   <-  42
txtFirstName.Width <-  60
txtFirstName.Text  <- staff.FirstName
employeeRecord.Controls.Add txtFirstName

// Label: Last Name
let lblLastName = new Label()
lblLastName.Left  <- 21
lblLastName.Top   <- 71
lblLastName.Width <- 96
lblLastName.Text  <- "Last Name:"
employeeRecord.Controls.Add lblLastName

// Text Box: Last Name
let txtLastName = new TextBox()
txtLastName.Left  <- 125
txtLastName.Top   <-  68
txtLastName.Width <-  60
txtLastName.Text  <- string staff.LastName
employeeRecord.Controls.Add txtLastName

// Label: Department Record Separator
let lblDepartmentRecord = new Label();
lblDepartmentRecord.Left   <-  20
lblDepartmentRecord.Top    <-  98
lblDepartmentRecord.Width  <- 360
lblDepartmentRecord.Height <-  13
lblDepartmentRecord.Text   <- "Department Record _______________________________________________"
employeeRecord.Controls.Add lblDepartmentRecord

// Label: Department Code
let lblDepartmentCode = new Label()
lblDepartmentCode.Left  <-  21
lblDepartmentCode.Top   <- 132
lblDepartmentCode.Width <- 100
lblDepartmentCode.Text  <- "Department Code:"
employeeRecord.Controls.Add lblDepartmentCode

// Text Box: Department Code
let txtDepartmentCode = new TextBox()
txtDepartmentCode.Left  <- 125
txtDepartmentCode.Top   <- 129
txtDepartmentCode.Width <- 60
txtDepartmentCode.Text  <- staff.Department.DepartmentCode
employeeRecord.Controls.Add txtDepartmentCode

// Label: Department Name
let lblDepartmentName = new Label()
lblDepartmentName.Left  <-  21
lblDepartmentName.Top   <- 158
lblDepartmentName.Width <- 104
lblDepartmentName.Text  <- "Department Name:"
employeeRecord.Controls.Add lblDepartmentName

// Text Box: Department Name
let txtDepartmentName  = new TextBox()
txtDepartmentName .Left <- 125
txtDepartmentName .Top  <- 155
txtDepartmentName.Width <- 240
txtDepartmentName .Text <- staff.Department.DepartmentName 
employeeRecord.Controls.Add txtDepartmentName 

do Application.Run employeeRecord

This would produce:

Records and Enumerations

As an alternative, you can specify the values of the member when creating the object. Here is an example:

type Department = {
    DepartmentCode : string
    DepartmentName : string }

type Employee = {
    EmployeeNumber : string
    FirstName      : string
    LastName       : string
    Department     : Department
    Title          : string }

let dept = { DepartmentCode = "ADMN"; DepartmentName = "Administration, Admissions, and Students Affairs" }
let staff = {
    EmployeeNumber = "161138"
    FirstName = "Laura"; LastName = "Fannie"
    Department = { DepartmentCode = "ADMN"; DepartmentName = "Administration, Admissions, and Students Affairs" }
    Title = "Dean of Litterary Studies" }
   
   
 

Home Copyright © 2009-2015, FunctionX Home