I have this so far but it just outputs 0
Option Explicit On
Option Strict On
Option Infer Off
Public Class frmMain
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click
Dim inFile As IO.StreamReader
Dim intBill As Integer
Dim avg As Integer
Dim trueAvg As Integer
If IO.File.Exists("monthlyBills.txt") Then
inFile = IO.File.OpenText("monthlyBills.txt")
Do Until inFile.Peek = -1
Integer.TryParse(inFile.ReadLine, intBill)
avg += intBill
Loop
inFile.Close()
trueAvg = CInt(avg / 12D)
lblAvg.Text = trueAvg.ToString()
Else
MessageBox.Show("Cannot find the file.", "monthlyBills",
MessageBoxButtons.OK, MessageBoxIcon.Information)
lblAvg.Text = "N/A"
End If
End Sub
End Class
Here is the "monthlyBills.txt" text file:
141.71
156.75
179.25
141.71
130.19
115.05
95.65
86.78
85.45
79.99
98.45
126.78