
Public Class frmCombine

  Dim justices() As String = IO.File.ReadAllLines("Justices.txt")
  Dim presidents() As String = IO.File.ReadAllLines("USPres.txt")

  Private Sub btnBoth_Click(ByVal sender As System.Object,
                            ByVal e As System.EventArgs) Handles btnBoth.Click
    'Display justices who were also presidents
    Dim query1 = From line In justices
                 Let firstName = line.Split(","c)(0)
                 Let lastName = line.Split(","c)(1)
                 Let fullName = firstName & " " & lastName
                 Select fullName
    Dim query = From person In query1.Intersect(presidents)
                Select person
    IO.File.WriteAllLines("Both.txt", query.ToArray)
  End Sub

  Private Sub btnNoAppointments_Click(ByVal sender As System.Object,
                                      ByVal e As System.EventArgs) Handles btnNoAppointments.Click
    'Display presidents who made no Supreme Court appointments
    Dim query1 = From line In justices
                 Let president = line.Split(","c)(2)
                 Select president
    Dim query2 = From person In presidents
                 Select person
    Dim query = From pres In query2.Except(query1)
                Order By pres
                Select pres
    IO.File.WriteAllLines("Noappointments.txt", query.ToArray)
  End Sub

  Private Sub btnOr_Click(ByVal sender As System.Object,
                          ByVal e As System.EventArgs) Handles btnOr.Click
    'Display a combined list of presidents and justices
    Dim query1 = From line In justices
                 Let firstName = line.Split(","c)(0)
                 Let lastName = line.Split(","c)(1)
                 Let fullName = firstName & " " & lastName
                 Select fullName
    Dim query2 = From person In presidents
                 Select person
    Dim query = From person In query2.Concat(query1)
                Order By person
                Select person
                Distinct
    IO.File.WriteAllLines("Or.txt", query.ToArray)
  End Sub

End Class
