How can I display month(i) beside the minimum or maximum values. Let's say minimum was 12 and it was month January. I want it to be display beside the value of min or max. Is there any other way I can close the form when user clicked cancel and exit in InputBox? I don't know how to do it if rainfall(11) as "integer"
Code:
Dim Month = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
Dim rainfall(11) As Integer
Dim i_max, i_min As Integer
lstInput.Items.Add("Monthly Rainfall Input")
lstInput.Items.Add("----------------------")
For i = 0 To 11
' Input rainfall for each month, require non-negative numbers,
rainfall(i) = CInt(InputBox("Please enter the rainfall for " & Month(i), "Challenge 2 - Rainfall Statistics"))
' and display input on the form for the user to see
lstInput.Items.Add(rainfall(i) & " for " & Month(i))
total = total + rainfall(i)
avg = total / 12
Next
i_min = LBound(rainfall)
i_max = UBound(rainfall)
max = rainfall(i_min)
min = rainfall(i_min)
For i = i_min + 1 To i_max
If rainfall(i) > max Then
max = rainfall(i)
ElseIf rainfall(i) < min Then
min = rainfall(i)
End If
dispmin = "The minimum monthly rainfall was (" & min & ")" & Month(i)
dispmax = "The maximum monthly rainfall was(" & max & ")" & Month(i)
Next
' If the user clicks the Cancel button or enters an
' empty string, leave this Click handler immediately.
' Exit if the user clicks the Cancel button
'initialize variables to first month's (January's) rainfall
'look at rest of monthly rainfall data and update stats
'calculate results and display them - note that if more than one
'month tied for the max or min, only the first month is named as
'the max or min on the output.