Review/thoughts and tips of my Algorithm/ Code?

K

Kavy

Hello all..

I have userform, not linked to tables. I have textboxes which I caluclate
data from and then input that into tables.

So what I want to do is, make a budget program. The user enters a brand new
job, with a start date, end date, pay freq and rate and everything else.

Right now when this happens, I have it calculating the expected pay every
pay perird from now till an end date. The user will then enter the real pay
when the actual cheques come in.

The problem is, I want this code to be universial, so if someone is work the
normal 5 day shift with 2 days of it works, but if they work 14 days on and 7
days off it works.

It works now, but I am trying to add overtime to be included, and it is
turning into a beast.

any suggestion are weclome, even small tibits!

Thanks!

The process I am doing now is

<code>
Calculating the last day of the current shift
if the last day of the current shift is less then the end date then I
checking if its less then the current pay period and if it is I
checking how many days of the first shift are in that pay period.
Checking how many more full shifts are also in that first pay perid
Checking how many days of the last shift are in that first pay period
calculate the amount of hours in that pay period, and days and pay
if the last day of the shift is equal to the pay period I
calculate the hours in that payperiod
if the last day of shift is greater then the pay period I
check how many days are in thay pay period
if the last day of the curent shift is greater then the end date I
calculate how many working days before the end date
exit the loop
and i loop it!

</code>
Then I write to a table



There are also many varibles checking to make sure days dont get missed or
hit twice. But adding overtime on top is making it very ugly. Below is the
code, bewear, not a pretty site, only for those of age of theire majority in
there nation.

I only added the function in question to keep the space down.
Also..
My variables mean...

EDate = end date
Sdate = start date
LDOS = last day of shift
DSS = day of shift that started (tracks what days have been counted)
TWDF = total work days first, tracks the work days of the first shift if the
shift is over mutiple pay periods
TWDL = SAME AS above but last shift
DPPS = What day of shift the current pay peried ends
THPP(a)/TDPP(a)/TPPP(a) = tracks the money per shifts, and date and actual
hours to write in the table


<code>

Function AddTrans(rsttrans As Recordset, Salary As Currency, SDate As Date, _
EDate As Date, Tax As Single, donum As Double, vac As Single, rate As
Currency, PFreq As Single, _
pd As Date, DPP As Date, DSS As Integer, Dayon As Integer, Dayoff As
Integer, hpd As Single, _
job As String)

Dim a As Integer
Dim atotal As Integer
Dim TS As Integer
Dim LDOS As Date
Dim TSL As Integer
Dim TWDF As Integer
Dim TWDL As Integer
Dim TPPP(1000) As Currency
Dim THPP(1000) As Double
Dim TDPP(1000) As Date
Dim DPPS As Integer

TSL = Dayon + Dayoff
a = 1
TS = 0

LDOS = SDate + TSL - DSS

Do
If LDOS < EDate Then
If LDOS < DPP Then

If DSS <= Dayon Then
TWDF = TSL - Dayoff - DSS + 1
Else
TWDF = 0
End If

Do
TS = TS + 1
LDOS = LDOS + TSL
If LDOS >= DPP Then
Exit Do
End If
Loop

DPPS = TSL - (LDOS - DPP)

If DPPS < Dayon Then
TWDL = DPPS
DSS = 1 + DPPS
Else
TWDL = Dayon
DSS = 1
LDOS = LDOS + TSL
End If

THPP(a) = ((TWDF + TWDL) * (hpd)) + ((TS - 1) * (Dayon) * (hpd))

ElseIf LDOS = DPP Then

If DSS <= Dayon Then
TWDF = TSL - Dayoff - DSS + 1
Else
TWDF = 0
End If

THPP(a) = TWDF * hpd
DSS = 1
LDOS = LDOS + TSL
Else

DPPS = TSL - (LDOS - DPP)
If DPPS < Dayon Then
TWDF = DPPS - DSS + 1
DSS = DPPS + 1
Else
TWDF = Dayon - DSS + 1
DSS = 1
LDOS = LDOS + TSL
End If

THPP(a) = TWDF * hpd

End If
TPPP(a) = THPP(a) * rate
TDPP(a) = pd
a = a + 1
TS = 0
pd = pd + PFreq
DPP = DPP + PFreq

Else

DPP = EDate
If DSS <= Dayon Then
TWDF = TSL - Dayoff - DSS + 1
Else
TWDF = 0
End If

DPPS = TSL - (LDOS - DPP)
TWDF = DPPS - DSS + 1
THPP(a) = TWDF * hpd
TPPP(a) = THPP(a) * rate
TDPP(a) = pd
a = a + 1

Exit Do
End If
Loop

atotal = a - 1
a = 1

Do While (a <= atotal)
With rsttrans
..AddNew
!Do = donum
!NameT = "Work pay from " & job
!Expected = True
!TDate = TDPP(a)
!Amount = TPPP(a) * (1 - (Tax / 100)) * (1 + (vac / 100))
!Hours = THPP(a)
..Update
End With
a = a + 1
Loop


End Function

</code>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top