Question:
How can I have my username and high score next to each other in a listbox? VB.Net?
Benn
2011-12-23 07:18:45 UTC
Ok, so for my college course I have created a gamer using Visual Basic. The language it is coded in is VB.Net ( I Think ).

At the moment, my high scores is set out with the username on one line, then the score on the next line.

This is the code which is used for the scores:

---------------------------------------

Private Sub frmHighScores_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'sort array of records
Dim comp As New ScoresComparer
Array.Sort(frmRegistration.Accounts, comp)

'display all records in listbox
For ScoresCounter = 0 To 99
If frmRegistration.Accounts(ScoresCounter).strUsername <> Nothing Then
lstHighScores.Items.Add(frmRegistration.Accounts(ScoresCounter).strUsername)
lstHighScores.Items.Add(frmRegistration.Accounts(ScoresCounter).intScore)
End If

Next

End Sub

--------------------------------------

This lays out my scores like this:

Ben
14
James
13
Jake
12



I would like my highscores to be layed out like this:

Ben - 14
James - 13
Jake - 12



Can anybody help me with a solution to this problem?

Thanks in advance!
Three answers:
2011-12-23 07:24:52 UTC
If the high score is a string, you could simply concatenate the strings together.

Eliminate the second lstHighScores.Items.Add line and on the first line, do something like this:



Pseudocode below...

lstHighScores.Items.Add(firstnamestring & " " & highscorestring)
Asad Siddiqi
2011-12-23 07:22:06 UTC
Instead of using 2 list boxes, use 1 list box. Then in 1 string concatenate or format the name and scores

listScores.Items.Add(username + " " + score.toString());
?
2011-12-23 07:19:17 UTC
sorry bro. I ain't reading all that.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...