Question Bubble Sort Array Method, quick question

Joined
Dec 30, 2011
Messages
18
Programming Experience
3-5
Hey all,

Having a bit of the problem with the code shown below, i keep getting a conversion error from "string to integer is not valid" but I can't quite figure out why

Basically there is an " " seperated input string that holds a series of numbers, i want to split this up, populate an array with them, and then re-order them into numerical order 0 - 100 say.

As far as i can tell this should work, would very much appreciate a helping hand, thanks in advance!

VB.NET:
frmCustomReports.textbox1.Text = Row_Ignorer_List           'prints the original space seperated string in the original order

        Dim Arr() As String                                  'Declare an array which will hold all of the numbers 
        Arr = Row_Ignorer_List.Split(" ")              'splits up the string 
        Dim Row_Ignorer_list_2 As String = " "
        Dim i, j As Integer
        For i = 0 To Arr.Count - 2                         'if there are for example 10 items then arr(9) is the upperbound
            For j = i + 1 To Arr.Count - 1               'as start is from 0, we have to - 1 to give a true count.
                Dim Pos1 As Integer = Arr(i)            'creates a variable to hold array object i
                Dim pos2 As Integer = Arr(j)            'creates a variable to hold array object j
                If Arr(i) > Arr(j) Then                       'if I is greater than J it swaps them over
                    Arr(i) = pos2
                    Arr(j) = Pos1
                End If
            Next j
            Row_Ignorer_list_2 = Row_Ignorer_list_2 & Arr(i) & " "      'Creates a new space seperated string with the numbers in the new order
        Next i
        frmCustomReports.TextBox2.Text = Row_Ignorer_list_2             'displays them into a text box
 
My first guess would be that you have a double space in their somewhere, but that's just a guess because I don't have the actual project in front of me to run. You do, so you don't have to guess. When the exception is thrown, look at the actual data and see what it is. You can see what String it is that cannot be converted. In fact, you can look at the entire array contents.
 
your the man! I changed the " " space to "," so I could write the string to a msgbox and check on the string that was being entered into the above...low and behold a "," was appearing before the 1st item in the list. The program was effectivly trying to split ",20" for example into two numbers!

Thanks for
 
Back
Top