Int(n) = n+1? in 2003 VBA - Why?

hq3mkns1

New Member
Joined
Oct 30, 2006
Messages
4
THe following is text from my immediate window:

?int(ElapsedTimeN)
143
?int(144)
144
?ElapsedTimeN *1000
144000


Why is int(ElapsedTimeN) not 144

How can this be? Anyone with any thoughts?
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
How is ElapsedTimeN declared and how is its value being set/modified?
 
Upvote 0
Heres my code:

Function ElapsedTime(StartTime, EndTime, StartDay, EndDay, Format As String) As String

'Set Numerical Elapsed Time to Zero
Dim ElapsedTimeN As Double

ElapsedTimeN = 0
DayCount = Int(EndTime) - Int(StartTime)
DayLength = (EndDay - StartDay) * 24

'Calculate Mins on 1st Day
'Check it's a workday
If Weekday(Int(StartTime), vbMonday) < 6 Then

'If it's open and closed in a day take the closed time else take the End of Day time
If Int(EndTime) = Int(StartTime) Then CloseTime = EndTime Else CloseTime = Int(StartTime) + EndDay

If StartTime > CloseTime Then ElapsedTimeN = 0 Else ElapsedTimeN = ElapsedTimeN + ((CloseTime - StartTime) * 24)

End If

'Calculate Mins on Last Day
'Check It's a workday
If Weekday(Int(EndTime), vbMonday) < 6 Then

'If it's open and closed on the same day do nothing
If (Int(EndTime) = Int(StartTime)) Or (Int(EndTime) + StartDay > EndTime) Then
Else
'Otherwise add the hours until Endtime to the Duration
ElapsedTimeN = ElapsedTimeN + (EndTime - Int(EndTime)) * 24
End If
End If

'Check for a span of more that two days
If DayCount > 1 Then

'Start on the second day and run to the penultimate day
For TestDay = Int(StartTime) + 1 To Int(EndTime) - 1

If Weekday(Int(TestDay), vbMonday) < 6 Then

ElapsedTimeN = ElapsedTimeN + DayLength
End If

Next TestDay

End If

DayCount = Int(ElapsedTimeN / DayLength)
HourCount = Int(ElapsedTimeN - (DayCount * DayLength))
MinsCount = Int((ElapsedTimeN - Int(ElapsedTimeN)) * 60)

If Format = "d" Then TextOut = DayCount & "Days " & HourCount & "Hours " & MinsCount & "Mins"
If Format = "h" Then TextOut = (DayCount * DayLength) + HourCount & "Hours " & MinsCount & "Mins"
If Format = "m" Then TextOut = ((DayCount * DayLength) + HourCount) * 60 + MinsCount & "Mins"

ElapsedTime = TextOut

End Function
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,285
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top