Imports System.Collections

Public Class Context

  Dim fl As vbFile
  Dim x() As Single, y() As Single
  Dim plts As PlotStrategy
  '-----
  Public Sub setLinePlot()
    plts = New LinePlotStrategy()
  End Sub
  '-----
  Public Sub setBarPlot()
    plts = New BarPlotStrategy()
  End Sub
  '-----
  Public Sub plot()
    readFile()
    plts.plot(x, y)      'Utwórz dowolny rodzaj wykresu
  End Sub
  '-----
  Private Sub readFile()
    Dim xc As New ArrayList()
    Dim yc As New ArrayList()
    Dim sline As String
    Dim tmp As Single
    Dim i As Integer
    'Wczytaj dane z pliku
    fl = New vbFile("data.txt")
    fl.OpenForRead()

    While Not fl.fEOF
      sline = fl.readLine
      i = sline.IndexOf(" ")
      If i > 0 Then
        tmp = sline.Substring(0, i)
        xc.Add(tmp)
        tmp = sline.Substring(i + 1)
        yc.Add(tmp)
      End If
    End While
    'Kopiuj dane z kolekcji do tablic
    Dim xp(xc.Count - 1) As Single
    Dim yp(yc.Count - 1) As Single
    For i = 0 To xc.Count - 1
      xp(i) = CType(xc(i), Single)
      yp(i) = CType(yc(i), Single)
    Next i
    x = xp
    y = yp
    fl.closeFile()
  End Sub

End Class
