J'essaie de determiner la somme des valeurs se trouvant dans un fichier csv et me heurte depuis des heures à des difficultés. quelqu'un voudrait m'aider merci...
J'ai essayer avec a methode suivante:
Private Sub sumColumn(ByVal datei As String)
Dim fs As New FileStream(datei, FileMode.Open)
Dim sr As New StreamReader(fs)
Dim xcol As Integer
Dim columns As New List(Of Double)
If sr.ReadLine <> "" Then
xcol = sr.ReadLine.Split.Length
End If
Do While Not sr.EndOfStream
If sr.ReadLine <> "" Then
Dim text As String = sr.ReadLine
Dim kette() As String = text.Split()
Dim length As Integer = kette.Length
Dim iter As Integer
For iter = 2 To length - 1
Dim y As Integer
Dim yval As Integer
If Double.TryParse(kette(iter), yval) Then
y = yval
End If
columns.Item(iter - 2) += y
MsgBox(columns(iter - 1))
Next
End If
Loop
End Sub
le fichier est comme le suivant. Ce sont des valeurs de mesures d'une installation photovoltaique
Private Function sumColumn(ByVal datei As String) As List(Of Double)
Dim fs As New FileStream(datei, FileMode.Open)
Dim sr As New StreamReader(fs)
Dim xcol As Integer
Dim columns As New List(Of Double)
If sr.ReadLine <> "" Then
xcol = sr.ReadLine.Split.Length
Dim index As Integer = 0
Do While index < xcol - 2
columns.Add(0.0)
index += 1
Loop
End If
Do While Not sr.EndOfStream
Dim text As String = sr.ReadLine
If text <> "" Then
Dim kette() As String = text.Split()
Dim length As Integer = kette.Length
Dim iter As Integer
For iter = 2 To length - 1
Dim y As Integer
Dim yval As Integer
If Double.TryParse(kette(iter), yval) Then
y = yval
End If
columns.Item(iter - 2) += y
Next
End If
Loop
Return columns
End Function
Somme de colonnes dans un fichier csv
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.