Option Strict Off
Option Explicit On

Friend Class Form1
  Inherits System.Windows.Forms.Form

#Region "Windows Form Designer generated code "
  Public Sub New()
    MyBase.New()
    If m_vb6FormDefInstance Is Nothing Then
      If m_InitializingDefInstance Then
        m_vb6FormDefInstance = Me
      Else
        Try
          'For the start-up form, the first instance created is the default instance.
          If System.Reflection.Assembly.GetExecutingAssembly.EntryPoint.DeclaringType Is Me.GetType Then
            m_vb6FormDefInstance = Me
          End If
        Catch
        End Try
      End If
    End If
    'This call is required by the Windows Form Designer.
    InitializeComponent()
  End Sub
  'Form overrides dispose to clean up the component list.
  Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
    If Disposing Then
      If Not components Is Nothing Then
        components.Dispose()
      End If
    End If
    MyBase.Dispose(Disposing)
  End Sub
  Private components As System.ComponentModel.IContainer
  'Required by the Windows Form Designer
  Public ToolTip1 As System.Windows.Forms.ToolTip
  Public WithEvents lsSwimmers As System.Windows.Forms.ListBox
  Public WithEvents Label1 As System.Windows.Forms.Label
  Public WithEvents lbTime As System.Windows.Forms.Label
  'NOTE: The following procedure is required by the Windows Form Designer
  'It can be modified using the Windows Form Designer.
  'Do not modify it using the code editor.
  <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    Me.components = New System.ComponentModel.Container()
    Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
    Me.lsSwimmers = New System.Windows.Forms.ListBox()
    Me.Label1 = New System.Windows.Forms.Label()
    Me.lbTime = New System.Windows.Forms.Label()
    Me.SuspendLayout()
    '
    'lsSwimmers
    '
    Me.lsSwimmers.BackColor = System.Drawing.SystemColors.Window
    Me.lsSwimmers.Cursor = System.Windows.Forms.Cursors.Default
    Me.lsSwimmers.ForeColor = System.Drawing.SystemColors.WindowText
    Me.lsSwimmers.Location = New System.Drawing.Point(16, 8)
    Me.lsSwimmers.Name = "lsSwimmers"
    Me.lsSwimmers.RightToLeft = System.Windows.Forms.RightToLeft.No
    Me.lsSwimmers.Size = New System.Drawing.Size(121, 160)
    Me.lsSwimmers.TabIndex = 0
    '
    'Label1
    '
    Me.Label1.BackColor = System.Drawing.SystemColors.Control
    Me.Label1.Cursor = System.Windows.Forms.Cursors.Default
    Me.Label1.ForeColor = System.Drawing.SystemColors.ControlText
    Me.Label1.Location = New System.Drawing.Point(168, 8)
    Me.Label1.Name = "Label1"
    Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No
    Me.Label1.Size = New System.Drawing.Size(105, 17)
    Me.Label1.TabIndex = 2
    Me.Label1.Text = "Swimmer's time:"
    '
    'lbTime
    '
    Me.lbTime.BackColor = System.Drawing.Color.White
    Me.lbTime.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
    Me.lbTime.Cursor = System.Windows.Forms.Cursors.Default
    Me.lbTime.ForeColor = System.Drawing.SystemColors.ControlText
    Me.lbTime.Location = New System.Drawing.Point(168, 40)
    Me.lbTime.Name = "lbTime"
    Me.lbTime.RightToLeft = System.Windows.Forms.RightToLeft.No
    Me.lbTime.Size = New System.Drawing.Size(89, 25)
    Me.lbTime.TabIndex = 1
    '
    'Form1
    '
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(312, 213)
    Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lsSwimmers, Me.Label1, Me.lbTime})
    Me.Location = New System.Drawing.Point(4, 23)
    Me.Name = "Form1"
    Me.Text = "Show swimmers"
    Me.ResumeLayout(False)

  End Sub
#End Region

#Region "Upgrade Support "
  Private Shared m_vb6FormDefInstance As Form1
  Private Shared m_InitializingDefInstance As Boolean
  Public Shared Property DefInstance() As Form1
    Get
      If m_vb6FormDefInstance Is Nothing OrElse m_vb6FormDefInstance.IsDisposed Then
        m_InitializingDefInstance = True
        m_vb6FormDefInstance = New Form1()
        m_InitializingDefInstance = False
      End If
      DefInstance = m_vb6FormDefInstance
    End Get
    Set(ByVal Value As Form1)
      m_vb6FormDefInstance = Value
    End Set
  End Property
#End Region

  Dim swimmers As Collection = New Collection()
  Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
    Dim f As Short
    Dim S As String
    Dim sw As Swimmer
    Dim i As Short

    f = FreeFile()
    'wczytaj dane z pliku i utwórz obiekty
    FileOpen(f, VB6.GetPath & "\500free.txt", OpenMode.Input)
    While Not EOF(f)
      S = LineInput(f)
      sw = New Swimmer()          'tworzenie obiektu
      sw.init(S)                  'ładowanie danych
      swimmers.Add(sw)            'dodanie obiektu do kolekcji
    End While
    FileClose(f)
    'umieść nazwiska pływaków w liście
    For i = 1 To swimmers.Count()
      sw = swimmers.Item(i)
      lsSwimmers.Items.Add(sw.getName)
    Next i
  End Sub

  Private Sub lsSwimmers_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles lsSwimmers.SelectedIndexChanged
    Dim i As Short
    Dim sw As Swimmer
    i = lsSwimmers.SelectedIndex  'pobierz indeks wybranej pozycji w liście
    If i >= 0 Then
      sw = swimmers.Item(i + 1)   'pobierz pływaka
      lbTime.Text = sw.getTime    'wyświetl jego czas
    End If
  End Sub
End Class