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

Recommended Answers

All 6 Replies

Someone please help! It's urgent.

to get the variables display in your meesage try somethig like:

MsgBox("The Sum of Array Numbers is " & Sum & " and the Average is " & Average)

to check and see if the text box is empty:

if txtNumber.Text =  string.empty then
             ''put action here if it is empty
           
Else
              ''put action here if contains text
           
End If

ill look at the other bits if i have time

Here is an update for my program.


I still need help with:

1) 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.

2) 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?

3) 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(I) = I * 2
        Next

        Dim Sum As Integer
        Dim Average As Double

        For I = 0 To MyArray.GetUpperBound(0)

            Sum = Sum + 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
            If txtNumber.Text = String.Empty Then
                MessageBox.Show("You must enter a number less than 200", "Invalid Number Format", _
                                MessageBoxButtons.OK, MessageBoxIcon.Error)
            Else
                MessageBox.Show("The Sum of Array Numbers is " & Sum & " and the Average is " & Average)
            End If


        Catch OtherEx As Exception
            If txtNumber.Text = String.Empty Then
                MessageBox.Show(OtherEx.ToString, "Unknown Error", _
                                MessageBoxButtons.OK, MessageBoxIcon.Error)
            Else
                MessageBox.Show("The Sum of Array Numbers is " & Sum & " and the Average is " & Average)
            End If

        End Try


    End Sub

Can someone please point out if my code is correct so far according to what I need to do? I really need help because some of the instructions, I'm not clearly understanding..

I need help on a couple of things.

1) Is my MyArray set up correctly? I am suppose to use a For..Next loop to assign a value 10 larger than the index value to these variables. For example: MyArray(34) gets 33, MyArray (89) gets 99 etc. The loop should run only the number of times the user entered in the textbox.

2) Is my sum and average being calculated correctly? I'm creating a sum of the values contained in Myarray variable simultaneously while assigning the values in the same loop.


3) Is my IF..THEN checking for a blank value in the text? If not, how do I implement is correctly?

Thanks..

Here is my updated code:

Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompute.Click




        Dim bolFinished As Boolean

        Try

            Dim Number As Integer = Convert.ToInt32(txtNumber.Text)
            Dim MyArray As Integer()
            Dim Sum As Integer
            Dim Average As Double

            MyArray = New Integer(200) {}


            For I = 0 To MyArray.GetUpperBound(0)


                MyArray(I) = I * 2

            Next

            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)



            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("There was a problem...Please email customer service", "Unknown Error", _
                            MessageBoxButtons.OK, MessageBoxIcon.Error)

            If txtNumber.Text = String.Empty Then
                MessageBox.Show("You must enter a numberl ess than 200")
            End If


        End Try


    End Sub

Anyone available to help me with my above post?

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.