Need Help wiht project

billabong0202

Newcomer
Joined
Jan 4, 2004
Messages
2
for my vb.net class my teacher wants me to write a program that will display individual and team bastting statistics in a table. THe data is given to me in a text file. the form of the text file is "comma delimited" meaning that a comma separates the peices of data in a single line. A line of which looks like:
Davis,342,101,292
Smith,228,87,144

my problem is that when i use the split() function, i do not know how to loop it through the file so it not only splits the first line, but also it splits all of the lines. My second problem is that it separates the data ino a single vertical colum using the split funtion so instead of looking like above^^ it looks like:
Davis
342
101
292

How would i make it so i can have the name and numbers line up with the colum:
name:
times batted:
#of hits:
bases gained:

because the split is considered as one object so wouldnt it only line up wiht the colum name so it would look like
name: davis
342
101
292
times batted:
# of hits:
basses gained:
 
Last edited:
Assuming that the String Array that have the splitted data is called 'mySplit' you can use:

Visual Basic:
Dim lString As String    'Line string
   For i As Integer = 0 To mySplit.Length - 1
       Select Case i
           Case 0
               lString = "Name: "
           Case 1
               lString = "Times batted: "
           Case 2
               '...
           Case 3
               '...
       End Select

       lString &= mySplit(i)
       f.WriteLine(lString)
     Next
I think this will give you an idea...

Alex :D
 
thanks for you help alex! i figured out how to do what i wanted last night after hours of thinking. i was up till 4 am doing this but here is what i came up with:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim batstat As IO.StreamReader
batstat = IO.File.OpenText("C:\Documents and Settings\Matt Reilly\My Documents\Vb.Net Docs\batstat.txt")
Dim fmtzone As String
fmtzone = "{0,-7}{1,10}{2,10}{3,15}{4,15}"
ListBox1.Items.Add(String.Format(fmtzone, "Player", "At Bats", "Hits", "Average", "Slugging %"))
ListBox1.Items.Add("")
Dim b, b1, b2, c, c1, c2, ba, ba1, ba2, sp, sp1, sp2 As Double 'stats for players 1,2,3
Dim rl, fmtzone1 As String
rl = batstat.ReadLine
playerstats(rl, b, c, ba, sp, fmtzone1)
rl = batstat.ReadLine
playerstats(rl, b1, c1, ba1, sp1, fmtzone1)
rl = batstat.ReadLine
playerstats(rl, b2, c2, ba2, sp2, fmtzone1)
teamtotals(b, b1, b2, c, c1, c2, ba, ba1, ba2, sp, sp1, sp2, fmtzone1)
showleaders(c, ba1, sp)
End Sub
Sub playerstats(ByVal rl As String, ByRef b As Double, ByRef c As Double, ByRef ba As Double, ByRef sp As Double, ByRef fmtzone1 As String)
Dim statinfo(), a As String, d As Double, i As Integer
statinfo = Split(rl, ",")
a = statinfo(0) '= Name
b = CDbl(statinfo(1)) '= At Bats
c = CDbl(statinfo(2)) '= Hits
d = CDbl(statinfo(3)) '= Bases Gained
ba = battingave(b, c)
sp = sluggingper(d, b)
fmtzone1 = "{0,-7}{1,10}{2,10}{3,15:p3}{4,15:p3}"
ListBox1.Items.Add(String.Format(fmtzone1, statinfo(0), statinfo(1), statinfo(2), ba, sp))
ListBox1.Items.Add("")
End Sub
Function battingave(ByVal b As Double, ByVal c As Double) As Double
Dim Ba As Double
Ba = (c / b)
Return (Ba)
End Function
Function sluggingper(ByVal d As Double, ByVal b As Double) As Double
Dim Sp As Double
Sp = (d / b)
Return (Sp)
End Function
Sub teamtotals(ByVal b, ByVal b1, ByVal b2, ByVal c, ByVal c1, ByVal c2, ByVal ba, ByVal ba1, _
ByVal ba2, ByVal sp, ByVal sp1, ByVal sp2, ByVal fmtzone1)
Dim atbats, hits, Ave, Slug As Double
atbats = calcatbats(b, b1, b2)
hits = calchits(c, c1, c2)
Ave = calcave(ba, ba1, ba2)
Slug = calcslug(sp, sp1, sp2)
ListBox1.Items.Add("_____________________________________________________________")
ListBox1.Items.Add(String.Format(fmtzone1, "Totals", atbats, hits, Ave, Slug))
End Sub
Function calcatbats(ByVal b, ByVal b1, ByVal b2)
Dim atbats As Double
atbats = (b + b1 + b2)
Return (atbats)
End Function
Function calchits(ByVal c, ByVal c1, ByVal c2)
Dim hits As Double
hits = (c + c1 + c2)
Return (hits)
End Function
Function calcave(ByVal ba, ByVal ba1, ByVal ba2)
Dim ave As Double
ave = (ba + ba1 + ba2) / 3
Return (ave)
End Function
Function calcslug(ByVal sp, ByVal sp1, ByVal sp2)
Dim slug As Double
slug = (sp + sp1 + sp2) / 3
Return slug
End Function
Sub showleaders(ByVal c, ByVal ba1, ByVal sp)
ListBox1.Items.Add("Leaders")
ListBox1.Items.Add("Hits: Davis " & c)
ListBox1.Items.Add("Batting Average: Smith " & FormatPercent(ba1))
ListBox1.Items.Add("Slugging %: Davis " & FormatPercent(sp))

End Sub
End Class
 
I'm sorry but this code you posted is quite "unreadable"...
Format the text properly so we can help ok?

By the way... is it working fine now?

Alex :D
 
Back
Top