Greetings all:
I am just starting to learn visual basic and am running into a wall with code that I am writing. I need to take data from one file and put it in another. The input file, playerdata1.txt has names, atbats, and hits for a little league team. The output file needs to have a title, and colum names, same as above and the data for the team - same data as above but one derived field... average. I am just having one heck of a time trying to get this thing to loop and read all my input file, and when I call the derived field, it is giving me an error.
I am including the code that I wrote below... if anyone can help me out with this I would greately appreciate it. I am just a beginner so...
Option Compare Database
Option Explicit
Dim strName As String
Dim dHits As Double
Dim dAtBats As Double
Dim dAverage As Double
Public Sub Module()
Open "C:\playerdata1.txt" For Input As #1
Open "C:\playerstats1.txt" For Output As #2
Call Heading
Do While Not EOF(1)
Call ReadData(strName, dHits, dAtBats)
Call PrintLine(strName, dHits, dAtBats)
Loop
Close #1
Close #2
End Sub
Private Sub Heading()
Print #2, Tab; "Yellow Socks"
Print #2,
Print #2, "PLAYER"; Tab; "AT BATS"; Tab; "HITS"; Tab; "AVERAGE"
Print #2,
End Sub
Private Sub ReadData(strName As String, dHits As Double, dAtBats As Double, _
dAverage As Integer)
Input #1, strName
Input #1, dHits
Input #1, dAtBats
End Sub
Private Function dAverage(dHits As Double, dAtBats As Double) As Double
dAverage = dHits / dAtBats
End Function
Private Sub PrintLine(strName As String, dHits As Double, dAtBats As Double, _
dAverage As Double)
Print #2, strName; Tab; dHits, dAtBats; Tab; dAverage(dHits, dAtBats)
End Sub
I am just starting to learn visual basic and am running into a wall with code that I am writing. I need to take data from one file and put it in another. The input file, playerdata1.txt has names, atbats, and hits for a little league team. The output file needs to have a title, and colum names, same as above and the data for the team - same data as above but one derived field... average. I am just having one heck of a time trying to get this thing to loop and read all my input file, and when I call the derived field, it is giving me an error.
I am including the code that I wrote below... if anyone can help me out with this I would greately appreciate it. I am just a beginner so...
Option Compare Database
Option Explicit
Dim strName As String
Dim dHits As Double
Dim dAtBats As Double
Dim dAverage As Double
Public Sub Module()
Open "C:\playerdata1.txt" For Input As #1
Open "C:\playerstats1.txt" For Output As #2
Call Heading
Do While Not EOF(1)
Call ReadData(strName, dHits, dAtBats)
Call PrintLine(strName, dHits, dAtBats)
Loop
Close #1
Close #2
End Sub
Private Sub Heading()
Print #2, Tab; "Yellow Socks"
Print #2,
Print #2, "PLAYER"; Tab; "AT BATS"; Tab; "HITS"; Tab; "AVERAGE"
Print #2,
End Sub
Private Sub ReadData(strName As String, dHits As Double, dAtBats As Double, _
dAverage As Integer)
Input #1, strName
Input #1, dHits
Input #1, dAtBats
End Sub
Private Function dAverage(dHits As Double, dAtBats As Double) As Double
dAverage = dHits / dAtBats
End Function
Private Sub PrintLine(strName As String, dHits As Double, dAtBats As Double, _
dAverage As Double)
Print #2, strName; Tab; dHits, dAtBats; Tab; dAverage(dHits, dAtBats)
End Sub