Hello, I need help with a few things. Most of these things, I tried to do, but I need to know if I did them correctly, if not, how do I fix my problem? Thanks.
1) How do I make my MessageBox.Show say "The Sum of Array Numbers is ____ and the Average is _____" with the dashes filled in with the identifers Sum and Average.
2) For my For...Next Loop, how do I make it so I assign a value 10 larger than the index value to the variables. For example, MyArray (34) gets 44.. Another example is MyArray (89) gets 99 etc. The Loop should run only the number of times user entered in the text box. For example, if the user entered 90 then the loop should run 90 times without hard coding the index value in the loop.
3) I need to create a sum of the values contained in MyArray variable simultaneously while assigning the values in the same loop. Then I need to find the average of these numbers after the loop finishes. Did I do this correctly in my code?
4) How do I use If..Then to check for a blank value in the text box. Without using IsNumeric, FormatException is suppose to handle the problem.
Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompute.Click
Dim MyArray As Integer()
MyArray = New Integer(200) {}
For I = 0 To MyArray.GetUpperBound(0)
MyArray(0) = 10
Next
Dim Sum As Integer
Dim Average As Double
For I = 0 To MyArray.GetUpperBound(0)
Sum = Sum + MyArray(I)
Next
Average = Sum / MyArray.GetUpperBound(0)
MessageBox.Show("The Sum of Array Numbers is" & Sum, "and the Average is" & Average)
Dim bolFinished As Boolean
txtNumber.Text = ""
bolFinished = False
Try
Dim Num As Integer = Convert.ToInt32(txtNumber.Text)
Sum = Sum + Num
txtNumber.Text = Sum.ToString()
bolFinished = True
Catch formatExceptionParameter As FormatException
MessageBox.Show("You must enter a number less than 200", "Invalid Number Format", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
Catch OtherEx As Exception
MessageBox.Show(OtherEx.ToString, "Unknown Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
If bolFinished = True Then
MessageBox.Show("Divison operation finished")
Else
MessageBox.Show("Computation operation failed")
End If
End Try
End Sub