Take a look to my code and help me please
They ask me to do this project
Please read carefuly and Help me what you can and want.
thankx
1. Create a project to process payroll information for Ace Industries Inc.
2. Project has to use at least 3 forms: Payroll form, DataEntry form and Salary form (feel free to add other forms and standard modules.)
3. Create a sequential file and call it Employee. Each record will contain fields for first name, last name, hourly pay rate and amount earned. Starting the project will load the employee data into an array of userdefined types from the sequential file.
4. DataEntry form allows adding new employee to the file and printing the list of all Ace Industries Inc employees and their rates. (Supposed all of them have different first names ).
5. Salary form retrieves salary information including first name, last name, pay rate, worked hours, overtime and salary. Overtime counts as worked hours over 40. Employees receive for overtime timeandahalf pay. The user has a choice to include salary information in the report or ignore it.
6. Payroll Form
a) Allows switching to the DataEntry form.
b) Allows selecting any employee
c) Allows finding any employee using employee first name
d) Allows calculating of a salary and printing report.
7. Add to the Payroll form FindPay command button or menu command for calculating salary. It has to be accessible only after selecting any employee. Use InputBox to enter worked hour's information.
8. Printing report should contain the list of first and last names, worked hours and overtime hours, pay rate, salary and total amount earned for all employees.
9. First name, last name, hourly pay rate and amount earned have to be automatically saved in the Employee file.
10. For self-checking use this table:
Employee Name Hours Worked Hours Overtime Pay rate Amount Earned
Janice Jones 40 0 5.25 210.00
Chris O’Connell 35 0 5.35 187.25
Karen Fish 45 5 6.00 285.00
Tom Winn 42 2 5.75 247.25
This is my code so far
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Option Explicit
Private Type worker
FName As String * 15 ' only 15 characters
LName As String * 15 ' only 15 characters
End Type
Dim NewWorker(1 To 50) As worker
Private Sub cmdAdd_Click()
Open "a:\Students.txt" For Append As #3
With NewWorker(3)
.FName = txtFirst.UBound
.LName = txtLast.UBound
Write #3, .FName, .LName
End With
Close #3
End Sub
Private Sub cmdInput_Click()
Dim i As Integer
Dim Counter As Integer
i = 1
Open "a:\Students.txt" For Input As #3 'open file
Do Until EOF(3)
With NewWorker(i)
Input #3, .FName, .LName
i = i + 1
End With
Loop
Close
Counter = i - 1
For i = 1 To Counter 'retrieve information from aour counter to our list box
With NewWorker(i)
List1.AddItem .FName & .LName
End With
Next
End Sub
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
Can someone help me the List1.AddItem doesn't work and this is getting me CRAZYYYYY
Please some help
[email protected]
Re: Take a look to my code and help me please
Several things to consider.
General Declarations:
You are limiting your NewWorkers array to only 50 workers. Make a module and put the type and array declarations in it like:
Public Type worker
FName As String * 15 ' only 15 characters
LName As String * 15 ' only 15 characters
End Type
Public NewWorkers() as Worker
Then, when you add to the NewWorkers Array use the following code
Redim Preserve NewWorkers(UBound(NewWorkers)+1)
NewWorkers(UBound(NewWorkers)).FName = txtFirst.Text
This will not limit your Array to 50
Add Procedure:
You are using NewWorker(3) which just replaces the third Item in the NewWorker array
Again.. use:
Redim Preserve NewWorker(UBound(NewWorker)+1)
NewWorker(UBound(NewWorker)).FName = txtFirst.Text
I dont think you want txtFirst.UBound try txtFirst.Text
Input Procedure:
First of all.. you want to Redim your array here...to clear it before you start writing to it again. This is important if the number of records has changed.
Redim NewWorkers(0) 'Notice there is no preserve here
You also want to clear your listbox otherwise you just continue to add to it.
List1.Clear
Also.. be aware that you will have to redim your array before every addition to the array if you use the dynamic array method I suggest.
Note:
Re Dimensioning the array is not the fastest method because it does require the redimension to take place before every addition. But it is safe in that you will never run into errors with users trying to add more records than the dimensioned limit of the array.
So if speed is not a concern.. it should work fine.
Good Luck
Joe
Re: Take a look to my code and help me please
I tried an excerpt of your code (I added some names to NewWorker() using your worker type and then used your code to display them in the list box) and it worked fine for me. What exact problems are you having?
IMHO a better way to iterate over an array is to use LBound and UBound rather than storing some number like Counter.
For example
for i = LBound(NewWorker) to UBound(NewWorker)
...
code
...
next i
-K