I am having a couple of problems. First, when I enter a number into the text box and hit enter It prints the number 12 times in the listbox. I only need one at a time. The other problems are the low price and average price. Can't get them to calculate properly. If anyone can help me figure this out, I would greatly appreciate it. Thanks!
Option Strict On Public Class gasPrice Dim priceArray(11) As Decimal Dim numprice As Decimal = 0 Private Sub enterButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles enterButton.Click For i = 0 To priceArray.GetUpperBound(0) priceArray(i) = Convert.ToDecimal(priceTextBox.Text) priceListBox.Items.Add(priceTextBox.Text) Next priceTextBox.Clear() End Sub Private Sub highButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles highButton.Click Dim highest As Decimal = 0 Dim highmonth As Integer = 0 For index As Integer = 0 To priceArray.GetUpperBound(0) If priceArray(index) > highest Then highest = priceArray(index) highmonth = index + 1 End If Next resultLabel.Text = "The highest price is " & highest & " in month " & highmonth End Sub Private Sub lowButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lowButton.Click Dim lowest As Decimal = 0 Dim lowmonth As Integer = 0 For index As Integer = 0 To priceArray.GetUpperBound(0) If priceArray(index) < lowest Then lowest = priceArray(index) lowmonth = index + 1 End If Next resultLabel.Text = "The lowest price is " & lowest & " in month " & lowmonth End Sub Private Sub avgButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles avgButton.Click Dim average As Decimal = 0 Dim total As Decimal = 0 For i = 0 To priceArray.GetUpperBound(0) total += priceArray(i) Next 'average = CLng(total) \ 11 resultLabel.Text = "The Average Price is: " & average End Sub End Class
Last edited by a moderator: