0

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

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

.csv 文件按此顺序排列

日期格式为 dd/mm/yy
当前时间
当前温度
当前湿度
当前露点
当前风速
当前阵风
当前风向

10/04/2012,00:00,6.439582,79.71528,3.13889,8.868753,33,33,264.8125 11/04/2012,00 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 中打开和输出它们。

Option Strict On 选项显式打开

Imports System.IO 导入系统

公开课形式1

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 平均值的任何想法?

4

0 回答 0