Public Class frmCountry

  Structure Nation
    Dim name As String
    Dim continent As String
    Dim population As Double  'in millions
    Dim area As Double        'in square miles
  End Structure

  Dim nations(191) As Nation

  Private Sub frmCountry_Load(ByVal sender As System.Object,
                              ByVal e As System.EventArgs) Handles MyBase.Load
    'Place the contents of UN.txt into the array nations
    Dim line As String
    Dim data() As String
    Dim countries() As String = IO.File.ReadAllLines("UN.txt")
    For i As Integer = 0 To 191
      line = countries(i)
      data = line.Split(","c)
      nations(i).name = data(0)
      nations(i).continent = data(1)
      nations(i).population = CDbl(data(2))
      nations(i).area = CDbl(data(3))
    Next
  End Sub

  Private Sub lstContinents_SelectedIndexChanged(ByVal sender As System.Object,
                                                 ByVal e As System.EventArgs) Handles lstContinents.SelectedIndexChanged
    Dim selectedContinent As String = lstContinents.Text
    lstCountries.Items.Clear()
    If selectedContinent = "Antarctica" Then
      MessageBox.Show("There are no countries in Antarctica.")
    Else
      For i As Integer = 0 To 191
        If nations(i).continent = selectedContinent Then
          lstCountries.Items.Add(nations(i).name)
        End If
      Next
    End If
  End Sub

End Class
