title: Reading from and manipulating a .csv file
body: <p>I have multiple .csv files for each month which go like:</p>
  
  <pre><code>01/04/2012,00:00,7.521527,80.90972,4.541667,5.774305,7,281.368
  02/04/2012,00:00,8.809029,84.59028,6.451389,5.797918,7,274.0764
  03/04/2012,00:00,4.882638,77.86806,1.152778,15.13611,33,127.6389
  04/04/2012,00:00,5.600694,50.35417,-3.826389,15.27222,33,40.05556
  </code></pre>
  
  <p>The format is : Date in the form dd/mm/yy,Current time,Current temperature,Current humidity,Current dewpoint,Current wind speed,Current wind gust,Current wind bearing</p>
  
  <p>The program needs to calculate the average for 
  temperature
  humidity
  wind speed
  wind direction</p>
  
  <p>and display them on a text box.</p>
  
  <p>any ideas?</p>
  
  <p>Here is what I have done so far...</p>
  
  <pre><code>Option Strict On
  Option Explicit On
  
  Imports System.IO
  Imports System
  
  Public Class Form1   
  
  Private Sub cmb1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmb1.SelectedIndexChanged
  
  End Sub
  
  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnexit.Click
      Me.Close()
  End Sub
  
  Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndata.Click
      'This is for August
      If cmb1.SelectedIndex = 1 Then
          TextBox1.Clear()
          Using reader As New StreamReader("c://temp/DailyAug12log.csv")
              Dim line As String = reader.ReadLine()
              Dim avgTemp As Integer
              Dim fields() As String = line.Split(",".ToCharArray())
              Dim fileDate = CDate(fields(0))
              Dim fileTime = fields(1)
              Dim fileTemp = fields(2)
              Dim fileHum = fields(3)
              Dim fileWindSpeed = fields(4)
              Dim fileWindGust = fields(5)
              Dim fileWindBearing = fields(6)
  
              While line IsNot Nothing
                  counter = counter + 1
                  line = reader.ReadLine()
              End While
              avgTemp = CInt(fields(2))
              avgTemp = CInt(CDbl(avgTemp / counter))
              TextBox1.Text = TextBox1.Text &amp; "Month = August" &amp; vbCrLf &amp; "Temperature Average: " &amp; avgTemp &amp; vbCrLf
          End Using
      End If
  End Sub
  
  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      Dim files() As String
      files = Directory.GetFiles("C:\Temp", "*.csv", SearchOption.AllDirectories)
      For Each FileName As String In files
          cmb1.Items.Add(FileName.Substring(FileName.LastIndexOf("\") + 1, FileName.Length - FileName.LastIndexOf("\") - 1))
      Next
  End Sub
  End Class
  </code></pre>