Hello im having trouble with my code !
we are asked to organize a list of names from a text.txt file the make them show up into a lits box (got that part down :) ) . then from the list box we are asked to create an array and sort that array (using our own sorting method) and organize the names using a button in assending order and another button organizing the array in decending order. the results from the orders names should appear in another list box .
i have gotten only the last name in the list to show up in the second list box but my code has no errors it just wont order the names properly! Help!!!!!

here is my code :)

Public Class FileSort

Dim sr As IO.StreamReader = IO.File.OpenText("C:\Users\Inspiron 15\documents\visual studio 2010\Projects\assigment4 EL\assigment4 EL\names.txt")
Structure names
  Dim c As Integer
 Dim fullname As String

End Structure
Dim allNames(99) As names

 Private Sub btnName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnName.Click

    Do While sr.Peek <> -1

        Name = sr.ReadLine

        LstNames.Items.Add(Name & " ")
    Loop
    sr.Close()

End Sub

Private Sub bubbelsort(ByRef names() As System.String, ByVal c As Integer)

    c = 0
    names(c) = sr.ReadLine()
    c = c * 1
    For c = 1 To 99 Step +1 '~~~ Addding (Z to A) to the the Listbox
        lstOrderedNames.Items.Add(Name & "")
    Next
End Sub

Private Sub BtnAssend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAssend.Click

    Dim names(99) As String

    Dim c As Integer
    c = 0
    Dim A As Integer
    A = 99

    names(c) = sr.ToString

    c = c + 1
    For c = 1 To 99 Step +1 '~~~ Addding (Z to A) to the the Listbox
        lstOrderedNames.Items.Add(Name & "")

    Next

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDessend.Click

    Dim names(99) As String

    Dim c As Integer
    c = 0
    Dim A As Integer
    A = 99

    names(c) = sr.ToString
    names(A) = sr.ToString

    A = A - 1
    For A = 99 To 0 Step -1 '~~~ Addding (Z to A) to the the Listbox

        lstOrderedNames.Items.Add(Name & "")

    Next

End Sub

Did you know you can override the Sort method of the ListBox?
Here is an example.

If, for example, you add the unordered list of names to listbox1, then you may transfer name by name to listbox2 just making sure before inserting you leave above the inserting index all names 'less than' the current one:

            For i As Int32 = 0 To ListBox1.Items.Count - 1
                Dim curr As String = ListBox1.Items(i)
                Dim j As Int32 = 0
                For j = 0 To ListBox2.Items.Count - 2
                    If curr < ListBox2.Items(j) Then Exit For
                Next
                ListBox2.Items.Insert(j, curr)
            Next

Of course in line 4. it should say -1 instead of -2.

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.