5 Replies - 1900 Views - Last Post: 24 May 2011 - 01:40 PM Rate Topic: -----

#1 ohmygod64  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 24-May 11

Sort "Scores" in order

Posted 24 May 2011 - 11:53 AM

I'm a beginner in programming and I'm not very good at it atm, so if you can give me a solution please make it as simple as possible. :)

Problem: I need to sort the numbers from biggest and smallest in a Text Document using VB console mode. Any ideas? :)

At the moment I've got this (not working):

Const Maxsize = 4

Sub Sort(ByRef TopScores() As TTopscores)
    Dim count as Integer
    Dim tempname as String
    Dim tempscore as Integer
    Dim flag as Boolean
    
    Do
      flag = True
      For count = 1 To (MaxSize - 1)
          If TopScores(count).Score < Topscores(count + 1).Score Then
             tempname = Topscores(count).Name
             tempscore = Topscores(count).Score
             Topscores(count).Name = TopScores(count + 1).Name
             TopScores(count).Score = TopScores(count + 1).Score
             TopScores(count + 1).Name = tempname
             TopScores(count + 1).Score= tempscore
             Console.ReadLine()
             Console.WriteLine(TopScores(count).Score)
             Console.ReadLine()
             flag = false
          End If
      Next
    Loop until (flag = True)
End Sub


This post has been edited by macosxnerd101: 24 May 2011 - 11:57 AM
Reason for edit:: Please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Sort "Scores" in order

#2 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1822
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: Sort "Scores" in order

Posted 24 May 2011 - 12:07 PM

It depends on what algorithm you prefer to use, take a look to this article:
Merge sort implementation

Also you may use ArrayList.Sort Method, look at its documentation

Also you may at this answered question on sorting alphabetically
Was This Post Helpful? 0
  • +
  • -

#3 ohmygod64  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 24-May 11

Re: Sort "Scores" in order

Posted 24 May 2011 - 12:53 PM

Thank you very much :)
The Merge Sort Algorithm is very useful!
Was This Post Helpful? 0
  • +
  • -

#4 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon

Reputation: 2298
  • View blog
  • Posts: 9,535
  • Joined: 29-May 08

Re: Sort "Scores" in order

Posted 24 May 2011 - 01:27 PM

Also consider implementing the IComparer interface. Tutorial
Was This Post Helpful? 0
  • +
  • -

#5 Btu  Icon User is offline

  • D.I.C Regular

Reputation: 36
  • View blog
  • Posts: 250
  • Joined: 16-May 11

Re: Sort "Scores" in order

Posted 24 May 2011 - 01:35 PM

I would just use a simple bubble sort.. but that's just me :bigsmile:
Was This Post Helpful? 0
  • +
  • -

#6 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon

Reputation: 2298
  • View blog
  • Posts: 9,535
  • Joined: 29-May 08

Re: Sort "Scores" in order

Posted 24 May 2011 - 01:40 PM

But why reimplement the sorting functionality, when the one provided by the framework is in a large percentage of the cases is suitable.

Array.Sort( yourArray, DirectCast(yourClass).Comparer)

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1