Public Class frmRandom
  Inherits System.Windows.Forms.Form

  ' ====================== Składniki ====================
  Private MyList As New clsList()

  Private mFileName As String
  Private CurrentRecord As Long
  Private LastRecord As Long

  ' Kod generowany przez Windows Form Designer 

  ' ====================== Właściwości =================
  Public Property FileName() As String
    Get
      Return mFileName
    End Get

    Set(ByVal NewFileName As String)
      mFileName = NewFileName
    End Set

  End Property

  ' ================= Zdarzenie ładowania formularza  ====================

  Private Sub frmRandom_Load(ByVal sender As System.Object, ByVal e As _
                  System.EventArgs) Handles MyBase.Load
    Dim i As Integer

    MyList.FileName = mFileName  ' Kopijemy nazwę otwartego pliku do klasy
    LastRecord = MyList.CurrentRecordCount ' Ile jest rekordów?
    CurrentRecord = 1
    If LastRecord > 0 Then         ' Jeśli są jakieś rekordy...
      FillARecord(1)               ' ...pokaż pierwszy z nich
    End If
  End Sub

  Private Sub btnAddNew_Click(ByVal sender As System.Object, ByVal e As _
                  System.EventArgs) Handles btnAddNew.Click
    Dim NewRecord As Long
    ClearForm()
    txtFirst.Focus()
  End Sub

  Private Sub ClearForm()   ' Wyczyść pola tekstowe
    txtFirst.Text = ""
    txtLast.Text = ""
    txtAddr.Text = ""
    txtCity.Text = ""
    txtState.Text = ""
    txtZip.Text = ""
  End Sub
  Private Sub txtState_Leave(ByVal sender As Object, ByVal e As _
                  System.EventArgs) Handles txtState.Leave
    txtState.Text = UCase(txtState.Text)  ' Zmień stan na duże litery 
  End Sub
  Private Sub FillARecord(ByVal rec As Long)
    ' Cel: ta procedura służy do wypełniania pól tekstowych formularza.
    '
    ' Lista argumentów:
    '  rec numer rekordu do odczytania (long integer)
    '
    Dim ErrorFlag As Integer

    ErrorFlag = MyList.ReadRecord(rec) ' Czytamy rekord klasy 
    If ErrorFlag = 0 Then
      Me.Text = "Random Access Files    Record: " & CStr(rec) 
                ' Wstawiamy tytuł formularza
      txtFirst.Text = MyList.First
      txtLast.Text = MyList.Last
      txtAddr.Text = MyList.Addr
      txtCity.Text = MyList.City
      txtState.Text = MyList.State
      txtZip.Text = MyList.Zip
    Else
      MessageBox.Show("Read failure")
    End If
  End Sub
