Need help on a Visual Basic programming problem
I just need to know how to set up this array within the program to allow 10 values to be entered then later be shown into separate labels as a largest and smallest value.
The question reads.
Largest/Smallest Array Values
Create an application that lets the user enter 10 values into an array. The application should display the largest and smallest values stored in the array. Figure 8-45 shows an example of the application's form after all 10 values have been entered, with the largest and smallest values displayed.
The form basically shows a large label box where your values will show up. Then two regular labels next to the boxed label that determines the largest and smallest values. There are four buttons, a clear, exit, Display Min & Max, and Input Values.
I have the actual program layout already made and the initial buttons already declared, being the exit and clear buttons. I just need to know how to setup the array's for the other two buttons.
If you can help it would be much appreciated.
Thanks
http://i22.photobucket.com/albums/b3...her/VBProg.jpg
Re: Need help on a Visual Basic programming problem
Quote:
Originally Posted by
jokers
I just need to know how to set up this array within the program to allow 10 values to be entered then later be shown into separate labels as a largest and smallest value.
The question reads.
Largest/Smallest Array Values
Create an application that lets the user enter 10 values into an array. The application should display the largest and smallest values stored in the array. Figure 8-45 shows an example of the application's form after all 10 values have been entered, with the largest and smallest values displayed.
The form basically shows a large label box where your values will show up. Then two regular labels next to the boxed label that determines the largest and smallest values. There are four buttons, a clear, exit, Display Min & Max, and Input Values.
I have the actual program layout already made and the initial buttons already declared, being the exit and clear buttons. I just need to know how to setup the array's for the other two buttons.
If you can help it would be much appreciated.
Thanks
http://i45.tinypic.com/2e219x1.jpg
Normally, I wouldn't do it using an InputBox, but if this is required then here it is:
Add this handler to the InputValues buton click event:
vb Code:
Private Sub btnInputValues_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnInputValues.Click
Dim userinput As String
Dim intvalues(9) As Integer
Do
userinput = InputBox("Enter 10 values (comma separated) in the field below:")
If userinput = "" Then Exit Sub ' Cancel was pressed.
Dim stringvalues() As String = userinput.Split(New Char() {","c}, StringSplitOptions.RemoveEmptyEntries)
' Possibly not necessary. It checks the input to be exactly 10 elements:
If stringvalues.Length <> 10 Then
MsgBox("Enter exactly 10 numbers.")
Continue Do
End If
' Checks each element to be an integer number:
For x As Integer = 0 To stringvalues.Length - 1
If Not Integer.TryParse(stringvalues(x), intvalues(x)) Then
MsgBox("Enter valid integer numbers.")
Continue Do
End If
Next
Exit Do
Loop
lblMaxNumber.Text = intvalues.Max.ToString
lblMinNumber.Text = intvalues.Min.ToString
End Sub
Re: Need help on a Visual Basic programming problem
Quote:
Originally Posted by
cicatrix
Normally, I wouldn't do it using an InputBox, but if this is required then here it is:
If using InputBox is a requirement then it could only be because this is homework, so is writing the code for the OP really appropriate? Using web resources is one thing but having someone else do your work for you is straight up cheating, even if that's not what the OP intended. Maybe helping people to think for themselves rather than thinking for them would be more appropriate.
Re: Need help on a Visual Basic programming problem
Quote:
Originally Posted by
jmcilhinney
If using InputBox is a requirement then it could only be because this is homework, so is writing the code for the OP really appropriate? Using web resources is one thing but having someone else do your work for you is straight up cheating, even if that's not what the OP intended. Maybe helping people to think for themselves rather than thinking for them would be more appropriate.
Quoted the whole OP's message just to be on the safe side.
Re: Need help on a Visual Basic programming problem
I would agree that posting the entire code really isn't all that appropriate. Also, i'm pretty sure that the point of the exercise is not to use the LINQ array extensions to get the maximum and minimum. I have a strong feeling that he is supposed to use more basic programming concepts to figure it out.
This is why .Net really isn't a good language to teach basic programming. It's a little too high-level.
Re: Need help on a Visual Basic programming problem
Using LINQ directly is not allowed also? :)
vb Code:
(Aggregate intval As Integer In intvalues Into Max()).ToString
I didn't learn how to write programs at school so I have no idea about how they teach it. Looking back, I see that in order to understand how machine works it would be better to start from the assembly language.
But since it's platform dependent I think Pascal has the best balance between complexity and simplicity.