Results 1 to 2 of 2

Thread: Test my program

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2001
    Posts
    4

    Unhappy Test my program

    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

    strMsg = "High Days:" & vbCrLf
    For lngCtr = LBound(arHigh, 2) To UBound(arHigh, 2)
    picAnswer.Print strMsg & "Date: " & Format(DateSerial(2000, 1, 1 + arHigh(0, lngCtr)), "mmm dd,yyyy") & " - Pollution: " & arHigh(1, lngCtr) & vbCrLf
    Next lngCtr


    End Sub

    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

    strMsg = "Low Days:" & vbCrLf
    For lngCtr = LBound(arLow, 2) To (UBound(arLow, 2))
    picAnswer.Print strMsg & "Date: " & Format(DateSerial(2000, 1, 1 + arLow(0, lngCtr)), "mmm dd,yyyy") & " - Pollution: " & arLow(1, lngCtr) & vbCrLf
    Next lngCtr
    picAnswer.Print strMsg

    End Sub

    Private Sub Form_Load()
    Dim textline As String
    Dim lngCtr As Long

    lngCtr = 0

    Open "pollution.txt" For Input As #1
    Do While Not EOF(1)
    Line Input #1, textline
    lngCtr = lngCtr + 1
    Loop

    Close #1

    End Sub
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width