Calcul de la somme des éléments d'une liste - Visual Basic

c'est mon premier temps à poster ici. Je vais avoir quelques difficultés avec un programme pour une classe, je suis prenant. J'ai besoin d'obtenir les miles et les gallons puis de calculer le MPG pour chaque entrée. J'ai cette partie compris. Ce que je n'arrive pas à obtenir est les totaux au bas. J'ai besoin d'ajouter la somme de tous les éléments dans chaque zone de liste et calculer le total des MPG chaque fois que le bouton est cliqué. Voici mon code si loin.

Public Class MilesPerGallon
Private Sub calculateMPGButton_Click(sender As System.Object,
ByVal e As System.EventArgs) Handles calculateMPGButton.Click
Dim miles As Double ' miles driven
Dim gallons As Double ' gallons used
Dim totalMiles As Double ' total miles driven
Dim totalGallons As Double ' total gallons used
Dim counter As Integer
miles = milesDrivenTextBox.Text ' get the miles driven
gallons = gallonsUsedTextBox.Text ' get the gallons used
If milesDrivenTextBox.Text <> String.Empty Then
' add miles to the end of the milesListBox
milesListBox.Items.Add(milesDrivenTextBox.Text)
milesDrivenTextBox.Clear() ' clears the milesDrivenTextBox
End If
If gallonsUsedTextBox.Text = 0 Then
' do not divide by 0 and alert 0
gallonsUsedTextBox.Text = "Cannot equal 0"
End If
If gallonsUsedTextBox.Text > 0 Then
' add gallons to the end of the gallonsListBox
gallonsListBox.Items.Add(gallonsUsedTextBox.Text)
mpgListBox.Items.Add(String.Format("{0:F}", miles / gallons))
gallonsUsedTextBox.Clear() ' clears the gallonsUsedTextBox
End If
totalMiles = 0
totalGallons = 0
counter = 0
Do While totalMiles < milesListBox.Items.Count
miles = milesListBox.Items(totalMiles)
totalMiles += miles
counter += 1
Do While totalGallons < gallonsListBox.Items.Count
gallons = gallonsListBox.Items(totalGallons)
totalGallons += gallons
counter += 1
Loop
Loop
If totalMiles <> 0 Then
totalResultsLabel.Text = "Total miles driven: " & totalMiles & vbCrLf &
"Total gallons used: " & totalGallons & vbCrLf & "Total MPG: " &
String.Format("{0:F}", totalMiles / totalGallons)
End If
End Sub
End Class

Merci d'avance pour toute aide que vous pouvez fournir.

InformationsquelleAutor CRunge | 2013-06-24