[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] btnSort_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] btnSort.Click[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] itemsMoved [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Boolean[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#0000ff]False[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]'USed to continue the DO loop, set to false when no items [/COLOR][/SIZE][SIZE=2][COLOR=#008000]Have been 'moved, [/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]'and there is an if statement after the for [/COLOR][/SIZE][SIZE=2][COLOR=#008000]loop that ends the do 'loop '(which [/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]'means we are finished) when [/COLOR][/SIZE][SIZE=2][COLOR=#008000]this value is false after the for 'loop...[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]'We dont need to start the for loop at 0 because there[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]'is no previous items to compare it with, so we start at 1 and[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]'from there on we compare it with "i-1" (the item before it)[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Do [/COLOR][/SIZE][SIZE=2][COLOR=#008000]'The boolean "notfinished" that i used was not needed at all, [/COLOR][/SIZE]
[SIZE=2][COLOR=#008000] 'this is more practicle ... [/COLOR][/SIZE][SIZE=2][COLOR=#008000]'this "Do" loop is terminated at the [/COLOR][/SIZE]
[SIZE=2][COLOR=#008000] 'end with "Exit Do" if there were no items moved[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff] Dim[/COLOR][/SIZE][SIZE=2] i [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer [/COLOR][/SIZE][SIZE=2][COLOR=#008000]'used to count our way through the array[/COLOR][/SIZE]
[SIZE=2] itemsMoved = [/SIZE][SIZE=2][COLOR=#0000ff]False[/COLOR][/SIZE][SIZE=2][COLOR=#008000]'set to false, set to true in if statement if [/COLOR][/SIZE]
[SIZE=2][COLOR=#008000] 'something [/COLOR][/SIZE][SIZE=2][COLOR=#008000]was moved[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff] For[/COLOR][/SIZE][SIZE=2] i = 1 [/SIZE][SIZE=2][COLOR=#0000ff]To[/COLOR][/SIZE][SIZE=2] ML.Length - 1 [/SIZE][SIZE=2][COLOR=#008000]'loop through the entire array[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000] 'Compare the current Track with the previous track, if the current track is [/COLOR][/SIZE]
[SIZE=2][COLOR=#008000] 'less than the last track, then ...[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff] If[/COLOR][/SIZE][SIZE=2] ML(i).Track < ML(i - 1).Track [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][SIZE=2][COLOR=#008000]'(the previous songs track is higher 'than this one)[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000] 'SmlSng will be the current song [/COLOR][/SIZE]
[SIZE=2][COLOR=#008000] 'BigSng will be the previous one [/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff] Dim[/COLOR][/SIZE][SIZE=2] SmlSng [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Song = ML(i) [/SIZE][SIZE=2][COLOR=#008000]'Create another instance of a song for[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000] 'this track (which is "smaller" than the previous track value)[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff] Dim[/COLOR][/SIZE][SIZE=2] BigSng [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Song = ML(i - 1) [/SIZE][SIZE=2][COLOR=#008000]'Create a new instance of a song for [/COLOR][/SIZE][SIZE=2][COLOR=#008000]this [/COLOR][/SIZE][SIZE=2][COLOR=#008000]track [/COLOR][/SIZE]
[SIZE=2][COLOR=#008000] '(which is "bigger" than[/COLOR][/SIZE][SIZE=2][COLOR=#008000] the current track value)[/COLOR][/SIZE]
[SIZE=2] ML(i) = (BigSng) [/SIZE][SIZE=2][COLOR=#008000]'Set the current song to the last one[/COLOR][/SIZE]
[SIZE=2] ML(i - 1) = SmlSng [/SIZE][SIZE=2][COLOR=#008000]'set the last song to the current one[/COLOR][/SIZE]
[SIZE=2] itemsMoved = [/SIZE][SIZE=2][COLOR=#0000ff]True[/COLOR][/SIZE][SIZE=2][COLOR=#008000]'Set to true so we know to do this loop again[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff] End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff] Next[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff] If[/COLOR][/SIZE][SIZE=2] itemsMoved = [/SIZE][SIZE=2][COLOR=#0000ff]False[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Exit[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Do [/COLOR][/SIZE][SIZE=2][COLOR=#008000]'if no items were moved on the last for loop, then we are finished[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Loop[/COLOR][/SIZE][SIZE=2][COLOR=#008000]'Start the for loop again[/COLOR][/SIZE]
[SIZE=2]lsvResults.Items.Clear() [/SIZE][SIZE=2][COLOR=#008000]'clears the listview[/COLOR][/SIZE]
[SIZE=2]Showlib() [/SIZE][SIZE=2][COLOR=#008000]'Reshows the listview items[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]'SaveLib() 'this saves the song array in its sorted state[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]