TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
johnmcguir
NA
1
0
Display string data from array in list box
Nov 9 2004 1:52 PM
As a student taking VB.net I am having a problem in a project. I have read a .txt file conststing of names, 4 rounds of golf scores anD total score for each name into 5 one-dimension arrays. I am trying to display the same records in a list box. The four scores and total score show fine but the name shows as Names(I) on each line (record). The records are in this form: Woods,Tiger 66 67 72 68 273. I will attempt to show you the code but I don't know how it is going to look. Please advise me on showing code if necessary. Also this is my first post so I am open to suggestions and constructive criticism about posting. Thanks Imports System.io Public Class Form1 Inherits System.Windows.Forms.Form ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'Programmer: John McGuire 'CIS400A 'Project 5 'Process golf scores '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Dim GolfScores As StreamReader Dim GolfOut As StreamWriter Dim ScoreCount As Integer Dim Names(30) As String Dim Round1(30) As Integer Dim Round2(30) As Integer Dim Round3(30) As Integer Dim Round4(30) As Integer Dim TotalScore(30) As Integer Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim NameAndScores As String GolfScores = New StreamReader("C:\temp\scores.txt") GolfOut = New StreamWriter("C:\temp\outscore.txt") Dim TheRecord As String Dim P As Integer = 0 'Position of "blank" in string Dim I As Integer = 0 'Counter for the number of players Dim Name As String Dim score1 As Integer Dim score2 As Integer Dim score3 As Integer Dim score4 As Integer 'Read data from text file into 5 arrays Do Until GolfScores.Peek = -1 NameAndScores = GolfScores.ReadLine() P = InStr(NameAndScores, " ") Names(I) = Microsoft.VisualBasic.Left(NameAndScores, P - 1) 'MsgBox(Names(I)) Round1(I) = LTrim(CInt(Mid(NameAndScores, P + 1, 2))) 'MsgBox(Round1(I)) Round2(I) = CInt(Mid(NameAndScores, P + 4, 2)) Round3(I) = CInt(Mid(NameAndScores, P + 7, 2)) Round4(I) = CInt(Mid(NameAndScores, P + 10, 2)) GolfOut.WriteLine(Names(I)) 'MsgBox(Names(I) & " " & Round1(I) & " " & Round2(I) & " " _ ' & Round3(I) & " " & Round4(I)) 'GolfOut.WriteLine(Round1(I)) 'GolfOut.WriteLine(Round2(I)) 'GolfOut.WriteLine(Round3(I)) 'GolfOut.WriteLine(Round4(I)) 'ComputeTotalScore(Round1, Round2, Round3, Round4, I) TotalScore(I) = Round1(I) + Round2(I) + _ Round3(I) + Round4(I) 'MsgBox(Names(I) & " " & TotalScore(I)) I += 1 'MsgBox(Names(I) & " " & Round1(I) & " " & Round2(I) & " " _ ' & Round3(I) & " " & Round4(I)) Loop 'Dim TotalByPlayer 'For I = 0 To UBound(Round1) 'TotalByPlayer = TotalByPlayer + Round1(I) + Round2(I) + _ 'Round3(I) + Round4(I) 'Next 'Close the file GolfScores.Close() End Sub 'Function to compute total score for each golfer '''''''''''''''''''''''''''''''''''''''''''''''''' 'Private Function ComputeTotalScore(ByVal Game1() As Integer, _ 'ByVal Game2() As Integer, ByVal Game3() As Integer, _ 'ByVal Game4 As Integer(), ByVal I As Integer) As Integer ' 'Dim I As Integer ' Return TotalScore(I) = Game1(I) + Game2(I) + Game3(I) + Game4(I) 'End Function 'Button to sort ascending according to total score. ''''''''''''''''''''''''''''''''''''''''''''''''''' Private Sub btnFinishOrder_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFinishOrder.Click Dim I As Integer = 0 Dim Temp As Integer Dim TempName As String Dim TempRnd1 As Integer Dim TempRnd2 As Integer Dim TempRnd3 As Integer Dim TempRnd4 As Integer Dim H As Integer = 3 'number of rounds Dim J As Integer For J = 0 To UBound(TotalScore) - 1 For I = 0 To H If TotalScore(I) > TotalScore(I + 1) Then 'MsgBox(TotalScore(I)) Temp = TotalScore(I) TotalScore(I) = TotalScore(I + 1) TotalScore(I + 1) = Temp TempName = Names(I) Names(I) = Names(I + 1) Names(I + 1) = TempName 'MsgBox(Names(I)) TempRnd1 = Round1(I) Round1(I) = Round1(I + 1) Round1(I + 1) = TempRnd1 TempRnd2 = Round2(I) Round2(I) = Round2(I + 1) Round2(I + 1) = TempRnd2 TempRnd3 = Round3(I) Round3(I) = Round3(I + 1) Round3(I + 1) = TempRnd3 TempRnd4 = Round4(I) Round4(I) = Round4(I + 1) Round4(I + 1) = TempRnd4 End If Next I Next J ShowFinishOrder(Names, Round1, Round2, Round3, Round4, _ TotalScore) End Sub 'Display finish order in text box '''''''''''''''''''''''''''''''''''''''''''''' Private Sub ShowFinishOrder(ByVal name() As String, ByVal Game1() _ As Integer, ByVal Game2() As Integer, ByVal Game3() As Integer, _ ByVal Game4() As Integer, ByVal totscore() As Integer) Dim I As Integer = 0 For I = 0 To UBound(name) ListBox1.Items.Add(name(I) & " " & (Game1(I)) & " " & _ (Game2(I)) & " " & (Game3(I)) & " " & (Game4(I)) & _ " " & (totscore(I))) 'ListBox1.Items.Add(Game1(I)) 'ListBox1.Items.Add(Game2(I)) 'ListBox1.Items.Add(Game3(I)) 'ListBox1.Items.Add(Game4(I)) 'ListBox1.Items.Add(totscore(I)) Next I End Sub ' Private Sub btnAlphaOrder_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAlphaOrder.Click ' Dim I As Integer = 0 ' Dim Temp As Integer 'Dim TempName As String 'Dim TempRnd1 As Integer ' Dim TempRnd2 As Integer ' Dim TempRnd3 As Integer 'Dim TempRnd4 As Integer ' Dim H As Integer 'Dim J As Integer ' For J = 0 To UBound(TotalScore) - 1 ' For I = 0 To H 'End Sub Private Sub btnQuit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnQuit.Click GolfOut.Close() Me.Close() End Sub End Class
Reply
Answers (
0
)
Cognos System Administrator
Programmer/Developer Needed