Ok, after I posted my last result, it came to my attention that I did the wrong assignment. Now I am really in need of help. THis is also a double arry assignment and I need help from anyone asap..please..The instructions are as follow:

I am to make modifications to the code below. The instruction further states that when the user clicks the Get Temperatures button, the button's Click event procedure should prompt the user to enter the highest and lowest temperatures for seven days. Store the temperatures in a seven-row, two-column Integer array. The first column should contain the highest temp, and the second column should contain the lowest temp. When the user clicks the Display High/low button, the button's Click event procedure should display the highest and lowest temperature contained in the array.

So, where is my starting point?

Private intTemps(9) As Integer
    Private intHighSub As Integer = intTemps.Length - 1

    Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

    Private Sub btnGet_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGet.Click
        ' gets the temperatures and stores them in the array

        Dim strInputTemp As String


        For intSub As Integer = 0 To intHighSub
            strInputTemp = InputBox("Temperature " & intSub + 1, "Temperatures")
            Integer.TryParse(strInputTemp, intTemps(intSub))
        Next intSub

        lblHighest.Text = String.Empty
        lblLowest.Text = String.Empty
    End Sub

    Private Sub btnDisplay_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
        ' display the highest and lowest temperature

        Dim intHigh As Integer
        Dim intLow As Integer

        intHigh = intTemps(0)
        intLow = intTemps(0)

        For intSub As Integer = 0 To intHighSub
            If intTemps(intSub) > intHigh Then
                intHigh = intTemps(intSub)
            End If
            If intTemps(intSub) < intLow Then
                intLow = intTemps(intSub)
            End If
        Next intSub

        lblHighest.Text = intHigh.ToString
        lblLowest.Text = intLow.ToString
    End Sub

Recommended Answers

All 4 Replies

My first attempt was to change the intTemp array to a intTem(8, 3) which shows the 7 row 2 column array, and I am lost after that

To start with, you'll declare the array as

Private intTemps(6, 1)

where the row numbers range from 0 to 6 and the columns from 0 to 1 (giving you 7 rows and 2 columns). To input the data you will have to prompt for two values for each of the seven rows so that looks like

For row As Integer = 0 To 6

Next

For each iteration you will have to prompt for (and validate) two values. The first value goes into intTemps(row,0) and the second into intTemps(row,1). Take it from there.

commented: Thank Rev. I will start on it and post what I got..Thank You +0

So, this is what I have so far. The thing is that when I click the display button to display the high temp and low temp, the high temp number shows up..so what I am missing?

Private intTemps(6, 1) As Integer
    Private intHighSub As Integer

    Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

    Private Sub btnGet_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGet.Click
        ' gets the temperatures and stores them in the array

        Dim strInputTemp As String


        For intSub As Integer = 0 To intTemps.GetUpperBound(0) - 1
            strInputTemp = InputBox("Temperature " & intSub + 1, "Temperatures")
            Integer.TryParse(strInputTemp, intTemps(intSub, 0))
        Next intSub

        lblHighest.Text = String.Empty
        lblLowest.Text = String.Empty
    End Sub

    Private Sub btnDisplay_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
        ' display the highest and lowest temperature

        Dim intHigh As Integer
        Dim intLow As Integer


        intHigh = intTemps(0, 0)
        intLow = intTemps(0, 0)

        For intSub As Integer = 0 To intTemps.GetUpperBound(0)
            If intTemps(intSub, 0) > intHigh Then
                intHigh = intTemps(intSub, 0)
            End If

            If intTemps(intSub, 1) < intLow Then
                intLow = intTemps(intSub, 1)
            End If
        Next intSub

        lblHighest.Text = intHigh.ToString
        lblLowest.Text = intLow.ToString

Try

Dim intHigh As Integer = intTemps(0,0)
Dim intLow As Integer = intTemps(0,1)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.