我在这个问题上被卡住了。我的代码总结了文本文件Dailyfile
中的所有数字,并将总数输出为AverageFile
。问题是我不想总结。我希望它找出所有数字的average
。我怎么能找到文本文件中的所有数字的平均值
我该怎么做?
Dim AverageFile As String = "C:\xxx\zzz\" & System.DateTime.Now.ToString("yyyyMMdd") & ".txt"
Dim DailyFile As String = "C:\xxx\xxx\" & System.DateTime.Now.ToString("yyyyMMdd") & ".txt"
Try
If System.IO.File.Exists(AverageFile) Then
Dim total As double = 0
For Each line As String In IO.File.ReadAllLines(DailyFile)
total += Double.Parse(line)
Next
Dim objWriter As New System.IO.StreamWriter(AverageFile, false)
objWriter.WriteLine(total.ToString)
objWriter.Close()
Else
'Nothing yet
End If
Catch ex As Exception
lbErrors.Items.Add(String.Concat(TimeOfDay & " Error 98: File or folder might not exist. Restart application... ", ex.Message))
End Try
Dailyfile
看起来像这样;
我已经尝试了一堆的total 0= double.parse(line)
的变化,因为我觉得这就是问题所在。我也试过diming the total as integer = 0
。我是新来的计算,所以我不知道事情是怎么回事。
尝试'File.ReadAllLines(路径)。选择(double.Parse)。平均()'。 – Enigmativity