从.csv文件组合框中读取和写入

时间:2013-05-06 20:04:59

标签: vb.net csv

我有10个.csv文件,这是每月天气日志,有8列 dd / mm / yy,当前时间,温度,湿度,dpoint,风速,阵风,风荷载。

应将文件放入组合框并打开,生成月平均值的输出并显示为

.csv文件按此顺序

日期格式为dd / mm / yy
当前时间
当前温度
当前湿度
当前露点
当前风速
目前阵风
目前的风力承载

10/04 / 2012,00:00,6.439582,79.71528,3.138889,8.868753,33,264.8125 11月4日/ 2012,00:00,7.853473,76.41666,3.701389,7.065973,33,277.4722 12月4日/ 2012,00:00,7.622221,64.99306,0.9236111,6.268749,33,214.9861 13/04 / 2012,00:00,7.24236,66.82639,1.319444,6.898612,33,136.8472 14/04 / 2012,00:00,6.952778,55.40278,-1.548611,10.11389,33,109.5764 15/04 / 2012,00:00,6.285417,56.97222,-2.243056,6.869443,33,137.4861 16/04 / 2012,00:00,7.205556,67.625,1.3125,8.19236,33,149.9514

我需要将选定月份的这些值输出到列表框并输出如下

月:2012年4月
温度平均:3.45
最高温度:54.34
最低温度:3.4
湿度:34.5
风速:3.45
阵风:54.34
风向:53.56

这是我的代码。到目前为止,我已经将文件名添加到组合框中,但我不确定如何在Visual Basic中打开和输出它们。

选项严格打开 选项明确的

导入System.IO 进口系统

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


        Dim total As Double = 0.0
    Using reader As New StreamReader("c://temp/DailyApr12log.csv")
        Dim line As String = reader.ReadLine()
        While line IsNot Nothing
            Dim fields() As String = line.Split(",".ToCharArray())
            total += Double.Parse(fields(7))
            line = reader.ReadLine()
        End While
    End Using
    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

结束班

有关如何在Visual Basic中输出.csv平均值的任何想法吗?

0 个答案:

没有答案