I'm trying to bubble sort an array then display it in a list box. When I click the button the program crashes.
Here is my code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Not TextBox1.Text = "" Then
ListBox1.Items.Add(TextBox1.Text)
ReDim Preserve numbers(numNumbers)
numbers(numNumbers) = CDbl(TextBox1.Text)
numNumbers += 1
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
BubbleSort(numbers)
For Each x In numbers
ListBox2.Items.Add(numbers(x).ToString())
Next
End Sub
And the compiler gives me this error: A first chance exception of type 'System.IndexOutOfRangeException' occurred in WindowsApplication1.exe