DevX Home Today's Headlines   Articles Archive   Tip Bank   Forums

# Thread: code for calculating work week

1. Greg Meghoo Guest

## code for calculating work week

I am teaching myself VB 6.0 on this project I need to write the correct code
for hours worked assuming a 8hr day, and assuming a 40hr week. When the user
enters the number 70, the application will display 1week, 3days, and 6hrs?
Can you help me to write the correct code I have been unsuccessful. Thanks  Reply With Quote

2. Aleksandr Guest

## Re: code for calculating work week

"Greg Meghoo" <gaameghoo@msn.com> wrote:
>
>I am teaching myself VB 6.0 on this project I need to write the correct

code
>for hours worked assuming a 8hr day, and assuming a 40hr week. When the

user
>enters the number 70, the application will display 1week, 3days, and 6hrs?
>Can you help me to write the correct code I have been unsuccessful. Thanks

This 2-minute code works as you want...

Public Function Elapsed(ByVal Total As Long)
Dim Wek As Long
Dim Day As Long
Dim Hrs As Long
Dim Rmn As Long

Rmn = Total
If Total > 40 Then
Wek = Int(Total / 40)
Rmn = Total - (Wek * 40)
End If

Total = Rmn
If Total > 8 Then
Day = Int(Total / 8)
Rmn = Total - (Day * 8)
End If

Hrs = Rmn

MsgBox "Weeks " & Trim(CStr(Wek)) & vbCrLf & _
"Days " & Trim(CStr(Day)) & vbCrLf & _
"Hours " & Trim(CStr(Hrs))
End Function  Reply With Quote

3. Greg Meghoo Guest

## Re: code for calculating work week

"Aleksandr" <aca@mailops.com> wrote:
>Still have trouble with the code I sent an attachment to your email

>"Greg Meghoo" <gaameghoo@msn.com> wrote:
>>
>>I am teaching myself VB 6.0 on this project I need to write the correct

>code
>>for hours worked assuming a 8hr day, and assuming a 40hr week. When the

>user
>>enters the number 70, the application will display 1week, 3days, and 6hrs?
>>Can you help me to write the correct code I have been unsuccessful. Thanks

>
>This 2-minute code works as you want...
>
>Public Function Elapsed(ByVal Total As Long)
> Dim Wek As Long
> Dim Day As Long
> Dim Hrs As Long
> Dim Rmn As Long
>
> Rmn = Total
> If Total > 40 Then
> Wek = Int(Total / 40)
> Rmn = Total - (Wek * 40)
> End If
>
> Total = Rmn
> If Total > 8 Then
> Day = Int(Total / 8)
> Rmn = Total - (Day * 8)
> End If
>
> Hrs = Rmn
>
> MsgBox "Weeks " & Trim(CStr(Wek)) & vbCrLf & _
> "Days " & Trim(CStr(Day)) & vbCrLf & _
> "Hours " & Trim(CStr(Hrs))
>End Function
>  Reply With Quote

4. D. Sainsbury Guest

## Re: code for calculating work week

Try Mod and \ function
i=70
Print i \ 40 'weeks
Print (i Mod 40) \ 8 'days
Print ((i Mod 40) Mod 8) 'remaining hrs
Greg Meghoo <gaameghoo@msn.com> wrote in message
news:39dcdf5d\$1@news.devx.com...
>
> I am teaching myself VB 6.0 on this project I need to write the correct

code
> for hours worked assuming a 8hr day, and assuming a 40hr week. When the

user
> enters the number 70, the application will display 1week, 3days, and 6hrs?
> Can you help me to write the correct code I have been unsuccessful. Thanks  Reply With Quote
#### Posting Permissions 