So i am making a registration program for conferences and when the user registers for a conference or workshop they have the option to print a schedule of what they have signed up for but i cant figure out how to sort the conference or workshop text files by the participant type which would be like /member, /guest or /advisor i put the / so i could find the type in the text file. I do realize that is would be much easier if i did a database but the user wants txt file so this is an example of the one of the conference txt files:

Members registered for the Washington conference.
Name: +rose brown
Participant Type: /Member
Chapter Number: #pc
Conference Code: <1234
Conference Date: November 7

Guests registered for the Washington conference.
Name: +megan randall
Participant Type: /Guest
Chapter Number: #fl
Conference Code: <1234
Conference Date: November 8

Advisors registered for the Washington conference.
Name: +mike done
Participant Type: /Advisor
Chapter Number: #nm
Conference Code: <
Conference Date: November 7

Recommended Answers

All 5 Replies

Consider making a List of conference classes out of the text file. Should be easy sortable any way you want.

You could just read them into some array of structures or class then sort them in memory. If you want to know what a particular person signed up for then sort the items by name, not by type.

Create a List as ddanbe stated. Then create a sort method that sorts the list based on the field that you want to use to sort it. The code below sorts by ConferenceDate, then ParticipantType, then by Participant.

Conference.vb

Public Class Conference
    Public Participant As String
    Public ParticipantType As String
    Public ChapterNumber As String
    Public ConferenceCode As String
    Public ConferenceDate As DateTime


    'constructor
    Public Sub New(ByVal Participant As String, _
                            ByVal ParticipantType As String, _
                            ByVal ChapterNumber As String, _
                            ByVal ConferenceCode As String, _
                            ByVal ConferenceDate As DateTime)

        Me.Participant = Participant
        Me.ParticipantType = ParticipantType
        Me.ChapterNumber = ChapterNumber
        Me.ConferenceCode = ConferenceCode
        Me.ConferenceDate = ConferenceDate

    End Sub

End Class

Declaration:

Private conferenceList As New List(Of Conference)

addTestDataToList:

    Private Sub addTestDataToList()
        conferenceList.Add(New Conference("Rose Brown", "Member", "pc", "1234", New DateTime(2014, 11, 7)))
        conferenceList.Add(New Conference("Megan Randall", "Guest", "fl", "1234", New DateTime(2014, 11, 8)))
        conferenceList.Add(New Conference("Mike Done", "Advisor", "nm", "1234", New DateTime(2014, 11, 7)))
        conferenceList.Add(New Conference("John Smith", "Member", "pc", "1234", New DateTime(2014, 11, 7)))
        conferenceList.Add(New Conference("Tom Brooks", "Member", "pc", "1234", New DateTime(2014, 11, 7)))
        conferenceList.Add(New Conference("Peter Davis", "Member", "pc", "1234", New DateTime(2014, 11, 8)))
        conferenceList.Add(New Conference("Jane Doe", "Guest", "nm", "1234", New DateTime(2014, 11, 7)))
        conferenceList.Add(New Conference("Bill Duncan", "Member", "fl", "1234", New DateTime(2014, 11, 8)))
        conferenceList.Add(New Conference("David Dolittle", "Member", "pc", "1234", New DateTime(2014, 11, 8)))
    End Sub

sort:

    Private Sub Sort(Optional ByVal nameSort As String = "firstname")

        'sorts by date, then by ParticipantType
        Dim tempConference As Conference

        'sort
        For i As Integer = 0 To conferenceList.Count - 2
            For j As Integer = i + 1 To conferenceList.Count - 1

                'sorts by Date
                If conferenceList(i).ConferenceDate > conferenceList(j).ConferenceDate Then

                    'swap
                    tempConference = conferenceList(i)
                    conferenceList(i) = conferenceList(j)
                    conferenceList(j) = tempConference
                ElseIf conferenceList(i).ConferenceDate = conferenceList(j).ConferenceDate Then

                    'sorts by ParticipantType
                    If conferenceList(i).ParticipantType > conferenceList(j).ParticipantType Then

                        'swap
                        tempConference = conferenceList(i)
                        conferenceList(i) = conferenceList(j)
                        conferenceList(j) = tempConference
                    ElseIf conferenceList(i).ParticipantType = conferenceList(j).ParticipantType Then

                        'sort by lastname
                        If (nameSort = "lastname") Then

                            'ensure Participant contains a first and last name
                            'which are typcially separated by a space
                            If conferenceList(i).Participant.Trim().Contains(" ") Then

                                'extract lastname
                                Dim iLastName As String = conferenceList(i).Participant.Substring(conferenceList(i).Participant.IndexOf(" ") + 1)
                                Dim jLastName As String = conferenceList(j).Participant.Substring(conferenceList(j).Participant.IndexOf(" ") + 1)

                                'extract first name
                                Dim iFirstName As String = conferenceList(i).Participant.Substring(0, conferenceList(i).Participant.IndexOf(" "))
                                Dim jFirstName As String = conferenceList(j).Participant.Substring(0, conferenceList(j).Participant.IndexOf(" "))

                                're-arrange name for comparison
                                Dim iTempName = iLastName & ", " & iFirstName
                                Dim jTempName = jLastName & ", " & jFirstName

                                If (iTempName > jTempName) Then
                                    'swap
                                    tempConference = conferenceList(i)
                                    conferenceList(i) = conferenceList(j)
                                    conferenceList(j) = tempConference
                                End If
                            End If
                        Else
                            'sorts by full name (firstname)
                            If conferenceList(i).Participant > conferenceList(j).Participant Then

                                'swap
                                tempConference = conferenceList(i)
                                conferenceList(i) = conferenceList(j)
                                conferenceList(j) = tempConference

                            End If
                        End If
                    End If
                End If

            Next
        Next

    End Sub

Usage:

  • sort()

or

  • sort("lastname")

Or you could just use python.

Or even better use perl

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.