Click here to Skip to main content
15,888,816 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: How to make text go away after a few seconds? Pin
William Winner14-Apr-10 8:28
William Winner14-Apr-10 8:28 
QuestionSplitting a .txt file and sorting it Pin
offroaderdan14-Apr-10 3:11
offroaderdan14-Apr-10 3:11 
AnswerRe: Splitting a .txt file and sorting it Pin
tosch14-Apr-10 3:42
tosch14-Apr-10 3:42 
GeneralRe: Splitting a .txt file and sorting it [modified] Pin
offroaderdan14-Apr-10 3:48
offroaderdan14-Apr-10 3:48 
GeneralRe: Splitting a .txt file and sorting it Pin
tosch14-Apr-10 4:15
tosch14-Apr-10 4:15 
GeneralRe: Splitting a .txt file and sorting it [modified] Pin
offroaderdan14-Apr-10 4:38
offroaderdan14-Apr-10 4:38 
GeneralRe: Splitting a .txt file and sorting it Pin
tosch14-Apr-10 4:48
tosch14-Apr-10 4:48 
AnswerRe: Splitting a .txt file and sorting it [modified] Pin
Ian Shlasko14-Apr-10 5:50
Ian Shlasko14-Apr-10 5:50 
1) Gotta get used to zero-indexed arrays/lists... In programming, everything starts at zero (Once you get beyond VB6)...

An array or list with 10 elements actually goes from 0 to 9. There's no element #10 (That would be the 11th element). If you count from 1 to 10, you skip the first element (0) and go past the last element (9).

2) When you're using the .NET framework, try not to reinvent the wheel. You shouldn't have to write your own sorting routine in most cases, because the framework already has those kinds of things built-in.

3) Try to think in terms of objects, not simple arrays. You're working with these things as arrays of strings and integers, when you're really dealing with high scores, each of which has a name and a value. You need to put them together so you can work with them more easily... That requires a class or structure...
Public Class HighScore
  Dim Name As String
  Dim Score As Integer
End Class


4) Once you put them together like this, it's a lot easier to shuffle them around as needed. If you have a List(Of HighScore), you can even automate the sorting by just calling the Sort() function. The only trick there is that you have to tell it how a HighScore should be sorted:
Public Class HighScore
  Implements System.IComparable(Of HighScore)

  Dim Name As String
  Dim Score As Integer

  Public Function CompareTo(ByVal other As HighScore) As Integer
    CompareTo = -Score.CompareTo(other.Score)
  End Function
End Class


Now a HighScore object knows that it should be sorted by score. Since we negate the result in the CompareTo function, it puts it in descending order instead of ascending order. When you tell the list to Sort(), it'll know what to do.

5) But then, you want to ALWAYS have it sorted, right? Well, the framework can do that too... Instead of a List(Of HighScore), try using a SortedList(Of HighScore). Then you don't have to do any work at all... When you add the new score in, it'll automatically jump to the right spot.

6) As for displaying them... Well, ListBoxes are pretty smart too... Now it's been a while since I've worked with WinForms (WPF is the new way to do things), but if I remember right, ListBoxes have a "DisplayMember" property. In this case, you can just set the DisplayMember of the two lists to "Name" and "Score" respectively, and then just add the HighScore objects to them. If the DisplayMember is "Name", the control will look for a "Name" property on the object you add, and display just that property.

Anyway, that should get you pointed in the right direction.
Proud to have finally moved to the A-Ark. Which one are you in?
Author of the Guardians Saga (Sci-Fi/Fantasy novels)

modified on Wednesday, April 14, 2010 12:14 PM

GeneralRe: Splitting a .txt file and sorting it Pin
offroaderdan15-Apr-10 0:12
offroaderdan15-Apr-10 0:12 
GeneralRe: Splitting a .txt file and sorting it Pin
Ian Shlasko15-Apr-10 1:37
Ian Shlasko15-Apr-10 1:37 
GeneralRe: Splitting a .txt file and sorting it Pin
offroaderdan15-Apr-10 1:52
offroaderdan15-Apr-10 1:52 
GeneralRe: Splitting a .txt file and sorting it Pin
Ian Shlasko15-Apr-10 1:58
Ian Shlasko15-Apr-10 1:58 
QuestionErrorprovider within a datatable column Pin
popalzai13-Apr-10 20:49
popalzai13-Apr-10 20:49 
AnswerRe: Errorprovider within a datatable column Pin
Simon_Whale14-Apr-10 3:30
Simon_Whale14-Apr-10 3:30 
GeneralRe: Errorprovider within a datatable column Pin
popalzai14-Apr-10 19:49
popalzai14-Apr-10 19:49 
GeneralRe: Errorprovider within a datatable column Pin
Simon_Whale14-Apr-10 21:55
Simon_Whale14-Apr-10 21:55 
QuestionHow to consume WCF service throgh Visual Basic 6.0 application Pin
amit k mistry13-Apr-10 10:28
amit k mistry13-Apr-10 10:28 
AnswerRe: How to consume WCF service throgh Visual Basic 6.0 application Pin
nlarson1113-Apr-10 11:08
nlarson1113-Apr-10 11:08 
GeneralRe: How to consume WCF service throgh Visual Basic 6.0 application Pin
amit k mistry13-Apr-10 11:21
amit k mistry13-Apr-10 11:21 
GeneralRe: How to consume WCF service throgh Visual Basic 6.0 application Pin
amit k mistry13-Apr-10 11:25
amit k mistry13-Apr-10 11:25 
GeneralRe: How to consume WCF service throgh Visual Basic 6.0 application Pin
nlarson1113-Apr-10 16:32
nlarson1113-Apr-10 16:32 
GeneralRe: How to consume WCF service throgh Visual Basic 6.0 application Pin
amit k mistry14-Apr-10 4:33
amit k mistry14-Apr-10 4:33 
GeneralRe: How to consume WCF service throgh Visual Basic 6.0 application Pin
nlarson1114-Apr-10 4:49
nlarson1114-Apr-10 4:49 
GeneralRe: How to consume WCF service throgh Visual Basic 6.0 application Pin
amit k mistry14-Apr-10 4:59
amit k mistry14-Apr-10 4:59 
GeneralRe: How to consume WCF service throgh Visual Basic 6.0 application Pin
nlarson1114-Apr-10 8:00
nlarson1114-Apr-10 8:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.