9 Replies - 2499 Views - Last Post: 09 April 2013 - 04:56 AM Rate Topic: -----

#1 x RadicalAura x  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 01-December 12

ListBox - Remove Duplicates, Alphabetize, Reverse

Posted 08 April 2013 - 06:10 PM

Populate lstOriginal with the given list of items:
In lstDupes, remove all duplicates contained in lstOriginal
In lstAlphabetized, arrange all items in the alphabetical order
In lstReverse, reverse the alphabetical order of the items

Requirements:
You MUST have 5 SubProcedures:
btnOrganize (Event Procedure) - the only action btnOrganize performs is declare variables and call other Subs. Note: if the button is clicked multiple times, lstDupes, lstAlphabetized, lstReverse do NOT change.
GetData (General Sub)
RemoveDupes (General Sub) - Use For Next loop
Alphabetize (General Sub) - Use For Next loop
Reverse (General Sub) - Use For Next loop

Public Class Form1
    Dim highestIndex As Integer
    Dim college As String

    Private Sub organizeButton_Click(sender As System.Object, e As System.EventArgs) Handles organizeButton.Click
        If lstOriginal.Items.IndexOf(college) Then
            For i = 0 To highestIndex
                college = (lstOriginal.Items(i))
                If lstOriginal.Items.IndexOf(college) = -1 Then
                    lstDupe.Items.Add(college)
                End If
            Next
        End If
    End Sub

    Sub GetData()


    End Sub

    Sub RemoveDupes()
        If lstOriginal.Items.IndexOf(college) Then
            For i = 0 To highestIndex
                college = (lstOriginal.Items(i))
                If lstOriginal.Items.IndexOf(college) = -1 Then
                    lstDupe.Items.Add(college)
                End If
            Next
        End If


    End Sub

    Sub Alphabetize()



    End Sub

    Sub Reverse()


    End Sub

End Class


This post has been edited by AdamSpeight2008: 08 April 2013 - 08:34 PM


Is This A Good Question/Topic? 0
  • +

Replies To: ListBox - Remove Duplicates, Alphabetize, Reverse

#2 x RadicalAura x  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 01-December 12

Re: ListBox - Remove Duplicates, Alphabetize, Reverse

Posted 08 April 2013 - 06:22 PM

Does it look like I'm on the right track with the loop? Sorry, I'm just trying to grasp the concept of loops the best I can. It's a new topic that was introduced to me last week and this is my first assignment involving them. I'm just having a hard time getting started but once I do, I'm sure it's all downhill from there.

Sorry for all the posts. Also, here is the list of content that goes within the original, first ListBox:
Michigan
Washington State
Oregon
Mare Island
Great Lakes
Harvard
California
California
USC
Washington
Notre Dame
Alabama
Stanford
Stanford
Georgia Tech
USC
Alabama
USC
USC
Columbia
Alabama
Pittsburgh
California
USC
USC
Stanford
Oregon State
Georgia
USC
USC
Alabama
Illinois
Michigan
Northwestern
Ohio State
Michigan
Illinois
USC
Michigan State
Ohio State
Michigan State
Iowa
Ohio State
Iowa
Washington
Washington
Minnesota
USC
Illinois
Michigan
UCLA
Purdue
USC
Ohio State
USC
Stanford
Stanford
USC
Ohio State
USC
UCLA
USC
Washington
USC
USC
Michigan
Washington
UCLA
UCLA
USC
UCLA
Arizona State
Michigan State
Michigan
USC
Washington
Washington
Michigan
Wisconsin
Penn State
USC
Ohio State
Michigan
Wisconsin
Wisconsin
Washington
Miami
Oklahoma
USC
Texas
Texas
USC
USC
USC
Ohio State
Was This Post Helpful? 0
  • +
  • -

#3 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: ListBox - Remove Duplicates, Alphabetize, Reverse

Posted 08 April 2013 - 08:11 PM

The assignment says that the button handler just calls the other subs. So that one is all wrong. Just call the other four subs there. The four subs should each populate their respective list boxes. I wouldn't try to manipulate your listboxes directly. Use arrays instead; they have methods you can call to do the jobs your instructor is asking for. In the button handler, declare all the arrays that you will be using, and pass the appropriate ones to the subs as arguments. Pass them by reference, so the changes that you make in the subs will be reflected in the arrays you declare here.

So, GetData should take all those values you've shown and put them in an array. It should then populate your original list box with them.

To remove duplicates, create another array. Use your for next loop to iterate (run through one by one) the first array. If the second array doesn't contain a value, add it (see here for an example).

Use a for next loop to populate your listbox with the second array. To get an alphabetized list, just sort the array (google "vb sort array" for examples). Populate your next listbox.

Then, to reverse the sort order, take the sorted array and do a reverse for next loop (example: For i from n to 0 step -1, where n is the upper bound of your array). Add the items to your final listbox as you go.

As you can see, googling for answers is an important skill. If you don't understand some of the suggestions I've given (upper bound of your array, for example), try googling for answers.

See if all that will help you. Have a go at a solution and post back if you have difficulties.

p. s. you may hear suggestions not to use arrays(List object, for example), but I have the feeling that your instructor wants you to start with them. You'll get the other ways to do it in good time.

This post has been edited by BobRodes: 08 April 2013 - 08:25 PM

Was This Post Helpful? 0
  • +
  • -

#4 x RadicalAura x  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 01-December 12

Re: ListBox - Remove Duplicates, Alphabetize, Reverse

Posted 08 April 2013 - 08:48 PM

Bob, thanks for your response. As far as I'm aware, I can just use loops for this project, not arrays but I know that we're inevitably going into arrays in the next unit. I feel quite ignorant asking this, but how exactly do you call and receive variables from one sub procedure to the event procedure? It's something that my instructor very vaguely described and none of our projects up until now have required it. Prior to this assignment, I've declared all of my variables as global, so I'm not familiar with this. Conceptually, I understand what the process is like, but I don't know what the syntax is like. Any insight? Thanks again.
Was This Post Helpful? 0
  • +
  • -

#5 x RadicalAura x  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 01-December 12

Re: ListBox - Remove Duplicates, Alphabetize, Reverse

Posted 08 April 2013 - 09:11 PM

Actually, I think I may have figured out how to call another sub... Not sure about receiving though.
Private Sub organizeButton_Click(sender As System.Object, e As System.EventArgs) Handles organizeButton.Click
        Dim highestIndex As Integer
        Dim college As String

        GetData()
        RemoveDupes()
        Alphabetize()
        Reverse()

    End Sub


Was This Post Helpful? 0
  • +
  • -

#6 x RadicalAura x  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 01-December 12

Re: ListBox - Remove Duplicates, Alphabetize, Reverse

Posted 08 April 2013 - 09:51 PM

  Private Sub btnOrganize_Click(sender As System.Object, e As System.EventArgs) Handles btnOrganize.Click

        Dim highestIndex As Integer
        Dim college As String

    End Sub

    Sub GetData(ByRef college As String, ByVal highestIndex As Integer)


    End Sub

    Sub RemoveDupes(ByRef college As String, highestIndex As Integer)
        If lstOriginal.Items.IndexOf(college) Then
            For i = 0 To highestIndex
                college = (lstOriginal.Items(i))
                If lstOriginal.Items.IndexOf(college) = -1 Then
                    lstDupe.Items.Add(lstOriginal.Items(i))
                End If
            Next
        End If


    End Sub

    Sub Alphabetize()



    End Sub

    Sub Reverse()


    End Sub

    Private Sub Chapter6Project1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

    End Sub

End Class


Is this looking better? I feel like I'm on the right track, but I only have the sub procedures receiving the other subs but the event procedure isn't calling them. I press the "organize list" button and nothing happens. :(/>

This post has been edited by x RadicalAura x: 08 April 2013 - 09:52 PM

Was This Post Helpful? 0
  • +
  • -

#7 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: ListBox - Remove Duplicates, Alphabetize, Reverse

Posted 08 April 2013 - 10:03 PM

You're on the right track. You need to learn to set breakpoints and step through your code. If you click in the left margin on a line of code, you will see a red dot appear. When you run your program, it will stop where the red dot is and you can then go to the immediate window below and evaluate stuff if you like. (in that window, entering "? x" will return the value of x, for example.) You can also step through your code one line at a time. Google that one, there are several ways to do it.

The reason that you aren't seeing anything happen is because you haven't put anything in GetData yet. So, when you call it, you aren't populating your list box, so when you call removedupes, you're working with an empty listbox, so nothing happens...yet. Work out GetData and you should start to see results.
Was This Post Helpful? 0
  • +
  • -

#8 x RadicalAura x  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 01-December 12

Re: ListBox - Remove Duplicates, Alphabetize, Reverse

Posted 08 April 2013 - 10:06 PM

View PostBobRodes, on 08 April 2013 - 10:03 PM, said:

You're on the right track. You need to learn to set breakpoints and step through your code. If you click in the left margin on a line of code, you will see a red dot appear. When you run your program, it will stop where the red dot is and you can then go to the immediate window below and evaluate stuff if you like. (in that window, entering "? x" will return the value of x, for example.) You can also step through your code one line at a time. Google that one, there are several ways to do it.

The reason that you aren't seeing anything happen is because you haven't put anything in GetData yet. So, when you call it, you aren't populating your list box, so when you call removedupes, you're working with an empty listbox, so nothing happens...yet. Work out GetData and you should start to see results.

Thanks, Bob. I'll give it my best!
Was This Post Helpful? 0
  • +
  • -

#9 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: ListBox - Remove Duplicates, Alphabetize, Reverse

Posted 08 April 2013 - 10:16 PM

Good job. Oh, your first one is right, your second one is wrong. Also, don't pass college in as an argument, use a for next loop to run through your listbox and populate the next one. (How you're going to sort without arrays is going to be complicated, though. Google "sort algorithms vb" for some information.)

This post has been edited by BobRodes: 08 April 2013 - 10:26 PM

Was This Post Helpful? 0
  • +
  • -

#10 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: ListBox - Remove Duplicates, Alphabetize, Reverse

Posted 09 April 2013 - 04:56 AM

I guess you could set Sorted = true on the listbox but I'm sure that's not the point of the exercise ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1