|
-
Apr 23rd, 2007, 12:14 AM
#1
Thread Starter
New Member
Help for a VB.net Noob
Good Evening! Please forgive me if a similar question has been asked before. I scoured the forum for hints, and I didn't find anything, so I don't think I am asking a redundant question. Here is the problem:
I have a project due tomorrow in which we have been given a program, and we need to alter the code so that it works using ByRef or ByVal subroutines instead of its present format. Here is the code:
Public Class Form1
Dim i As Integer = 0
Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
Dim name(3) As String
Dim rate(3) As Double
Dim hours(3) As Integer
Dim gross(3) As Double
Dim total As Double
Dim sr As IO.StreamReader = IO.File.OpenText("payroll.txt")
Dim format As String = "{0, -13}{1, -15:C2}{2, -16:N0}{3, -10:C2}"
Dim numberOfEmployees As Integer
'Input Section
Do While sr.Peek <> -1
i += 1
name(i) = sr.ReadLine
rate(i) = CDbl(sr.ReadLine)
hours(i) = CInt(sr.ReadLine)
Loop
numberOfEmployees = i
'Processing Section
For i = 1 To numberOfEmployees
If hours(i) <= 40 Then
gross(i) = hours(i) * rate(i)
Else
gross(i) = (rate(i) * 40) + ((rate(i) * 1.5) * (hours(i) - 40))
End If
total = total + gross(i)
Next i
'Output Section
For i = 1 To numberOfEmployees
'Display Report header
If i = 1 Then
With lstDisplay.Items
.Clear()
.Add("Payroll Report for week ending 03/23/07")
.Add(" ")
.Add(String.Format(format, "Employee", "Hourly Rate", "Hours Worked", "Gross Pay"))
.Add(" ")
End With
End If
'Issue Checks
lstDisplay.Items.Add(String.Format(format, name(i), " " & FormatCurrency(rate(i)), " " & hours(i), gross(i)))
Next i
lstDisplay.Items.Add(" ")
lstDisplay.Items.Add(String.Format(format, "Final Total", " ", " ", total))
End Sub
As you can see, it reads from a text file. The contents of this file are:
Al Adams
6.5
38
Bob Brown
5.7
50
Carol Coe
7
40
Please, please forgive me for being such a noob. I will accept any ridicule that you have to offer, as long as you might consider helping me. I am losing my mind!!!!!
Thank you!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|