Results 1 to 23 of 23

Thread: Removing unnecessary 0's from an array? " InvalidCastException was unhandled"

Threaded View

  1. #5

    Thread Starter
    Member
    Join Date
    Nov 2011
    Posts
    41

    Re: Removing unnecessary 0's from an array? " InvalidCastException was unhandled"

    Ok thanks you guys for the help but now the rest of my program wont work :/
    I get the following Error : ArguementOutOfRangerExceptin was unhandled. Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
    Code:
     Private Sub btnDisplayLargestNumber_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplayLargestNumber.Click
    
            Dim Largest As Integer
            Largest = MyArray(0)
            For J = 1 To 24
                If MyArray(J) > Largest Then
                    Largest = MyArray(J)
                End If
            Next
            txtDisplayNumbers.Text = CStr(Largest)
    
        End Sub
    
        Private Sub btnDisplaySmallestNumber_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplaySmallestNumber.Click
    
            Dim Smallest As Integer
            Smallest = MyArray(0)
            For J = 1 To 24
                If MyArray(J) < Smallest Then
                    Smallest = MyArray(J)
                End If
            Next
            txtDisplayNumbers.Text = CStr(Smallest)
    
        End Sub
        Private Sub btnDisplayRange_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplayRange.Click
    
            Dim Smallest As Integer
            Dim Largest As Integer
            Smallest = MyArray(0)
            Largest = MyArray(0)
            For J = 1 To 24
                If MyArray(J) < Smallest Then
                    Smallest = MyArray(J)
                ElseIf MyArray(J) > Largest Then
                    Largest = MyArray(J)
                End If
            Next
            txtDisplayNumbers.Text = _
            CStr(Smallest) & " to " & CStr(Largest)
    
        End Sub
        Private Sub btnDisplaySumOfNumbers_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplaySumOfNumbers.Click
    
            Dim Sum As Integer
            For J = 0 To 24
                Sum = Sum + MyArray(J)
            Next
            txtDisplayNumbers.Text = CStr(Sum)
    
        End Sub
    
    
        Private Sub btnDisplayMean_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplayMean.Click
            Dim lCounter As Long
            Dim dTotal As Double
            Dim dAverage As Double
    
            dTotal = 0
            For lCounter = 0 To UBound(Array)
                dTotal = dTotal + MyArray(CInt(lCounter))
            Next
            dAverage = dTotal / (UBound(Array) + 1)
            txtDisplayNumbers.Text = CStr(dAverage)
        End Sub
    End Class
    Last edited by Hack; Dec 13th, 2011 at 07:29 AM. Reason: Added Code Tags

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width