0

I'm trying to get buttons btnMaximum and btnMinimum to display the correct Max and Min numbers to a label. Each button is a separate button and when clicked will display either the max or min number.

I've got the array going but I dont know the proper functions for finding a Max and a Min.

Here is what I have so far:

Public Class Form1

Private Sub btnGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerate.Click
    Dim intNumbers(-1) As Integer
    Dim intCounter As Integer
    ReDim intNumbers(14)

    For intCounter = 0 To intNumbers.Length - 1
        intNumbers(intCounter) = Int((100 - 1 + 1) * Rnd()) + 1
        Me.lstNumbers.Items.Add(intNumbers(intCounter))
    Next
    ReDim Preserve intNumbers(14)
    lstNumbers.Items.Clear()
    For intCounter = 0 To intNumbers.Length - 1
        Me.lstNumbers.Items.Add(intNumbers(intCounter))
    Next


End Sub

Private Sub btnMaximum_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMaximum.Click


End Sub

Private Sub btnMinimum_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMinimum.Click

End Sub
End Class

I would really appreciate the help.

1

1 Answer 1

3

Firstly, you will need to move the declaration of your integer array outside of the click event for btnGenerate. This will allow you to access the array itself outside of that particular function (IE: inside your min and max button functions).

Arrays have two handy functions, Min and Max.

Dim intNumbers() As Integer = New Integer() {0, 1, 2, 3, 4, 5}
Dim intMin As Integer = intNumbers.Min          'will contain value 0
Dim intMax As Integer = intNumbers.Max          'will contain value 5
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.