I'm having that worst time trying to figure out what I am doing wrong. I've written a program that reads an input file containing daily pollution levels for the year 200 in Baltimore. The user should be able to click on one of three interface choices: Highest Pollution, Lowest Pollution, and Average Pollution. The only problem is it never selects from the text file, the answer always coms out to be a listing of everyday in the year with the level of 0, even the average comes out to 0. Here is the program I've written, please tell me what I'm doing wrong. I've also attached the text file.
Option Explicit
Dim arPollution(0 To 364) As Long
Private Sub cmdAvg_Click()
Dim lngCtr As Long
Dim lngSum As Long
Dim dblAvg As Double
picAnswer.Cls
lngSum = 0
For lngCtr = LBound(arPollution) To UBound(arPollution)
lngSum = arPollution(lngCtr) + lngSum
Next lngCtr
dblAvg = lngSum / (UBound(arPollution) + 1) picAnswer.Print "Average:" & Format(dblAvg, "00.000")
End Sub
Private Sub cmdHigh_Click()
Dim lngCtr As Long
Dim lngHigh As Long
Dim lngIdx As Long
Dim arHigh()
Dim strMsg As String
picAnswer.Cls
lngIdx = 0
lngHigh = 0
'First find the high pollution
For lngCtr = LBound(arPollution) To UBound(arPollution)
If arPollution(lngCtr) > lngHigh Then
lngHigh = arPollution(lngCtr)
End If
Next
'Now loop again finding all matching days
For lngCtr = LBound(arPollution) To UBound(arPollution)
If arPollution(lngCtr) = lngHigh Then
'2 dimensional array, 2 elements are DAY (position 0) and POLLUTION(position 1)
ReDim Preserve arHigh(2, lngIdx)
arHigh(0, lngIdx) = lngCtr
arHigh(1, lngIdx) = arPollution(lngCtr)
lngIdx = lngIdx + 1
End If
Next lngCtr
Private Sub cmdLow_Click()
Dim lngCtr As Long
Dim lngLow As Long
Dim lngIdx As Long
Dim arLow()
Dim strMsg As String
picAnswer.Cls
lngIdx = 0
lngLow = 999999
'First find the Low pollution
For lngCtr = LBound(arPollution) To UBound(arPollution)
If arPollution(lngCtr) < lngLow Then
lngLow = arPollution(lngCtr)
End If
Next
'Now loop again finding all matching days
For lngCtr = LBound(arPollution) To UBound(arPollution)
If arPollution(lngCtr) = lngLow Then
'2 dimensional array, 2 elements are DAY (position 0) and POLLUTION(position 1)
ReDim Preserve arLow(1, lngIdx)
arLow(0, lngIdx) = lngCtr
arLow(1, lngIdx) = arPollution(lngCtr)
lngIdx = lngIdx + 1
End If
Next lngCtr