Ok more Visual Basic 03 help

Soldato
Joined
20 Aug 2004
Posts
3,115
Location
Bournemouth
Yeah yeah I know I keep asking for help but this ones a little up from before.

Basically my program reads from a .text file and places the info in a list box. It lists line1 as column 1 and line2 as column2 etc to 4 columns, then lists the next 4 lines under those columns. like so:

Dim employee, hrate, hworked, gross As String
Dim fmtStr As String = "{0,-15}{1,15}{2,15}{3,15}"
Dim sr As IO.StreamReader = IO.File.OpenText("payroll.TXT")
lstnumbers.Items.Clear()
Do While sr.Peek() <> -1
employee = sr.ReadLine
hrate = sr.ReadLine
hworked = sr.ReadLine
gross = sr.ReadLine
lstnumbers.Items.Add(String.Format(fmtStr, employee, hrate, hworked, gross))
Loop
sr.Close()

What I need it to do now is every 4th line starting at "hworked = sr.ReadLine" to read the numbers and add them all up. For an unknown ammount of lines.
Also after that it has to use the average and check it against the values in the list then multiply large values by the number on the column before.

Basically its a list of peoples names, hours worked, and £ per hour.
 
So every 4th time you read the 'hworked' value, you want to add it? Not sure I completely follow what you are trying to do?
(i'm a c# man so this is just psuedo code, just correct the syntax if this is what you want to do)

Dim i as integer
Dim sum as integer
Dim count as integer
i = 0
sum = 0
count = 0

Do While sr.Peek() <> -1
i = i + 1
employee = sr.ReadLine
hrate = sr.ReadLine
hworked = sr.ReadLine
if (i == 4)
{
sum = sum + hworked
count = count + 1
i = 0
}
gross = sr.ReadLine

........... after you've finished up here:

Dim average
average = sum / count
 
Back
Top Bottom