M

#### millsy

having problems:

I am trying to input times as 4 digit integers then use the function

"TimeDiff" to work out the difference between times. Timediff works

fine if used in a spreadsheet cell. I then want to use this function

to work out a relationship between sets of different times. This

function is called "Findcase". Both are listed below. It seems that

the problem lies with the multiple use of TimeDiff within FindCase

because the first calculation WsRs = TimeDiff(Ws, Rs) seems to work but

the others do not. Perhaps it's just a bug in my code that I just

cannot see.

Any ideas?

Function TimeDiff(BeginTime As Integer, EndTime As Integer) As Single

Dim BeginHour As Integer, BeginMinute As Integer

Dim EndHour As Integer, EndMinute As Integer

If EndTime < BeginTime Then EndTime = EndTime + 2400

BeginHour = Int(BeginTime / 100)

BeginMinute = BeginTime - (BeginHour * 100)

BeginTime = (BeginHour * 60) + BeginMinute

EndHour = Int(EndTime / 100)

EndMinute = EndTime - (EndHour * 100)

EndTime = (EndHour * 60) + EndMinute

TimeDiff = (EndTime - BeginTime) / 60

End Function

Function FindCase(Ws As Integer, We As Integer, Rs As Integer, Re As

Integer) As Single

Dim WsRs As Single, RsWe As Single, WsWe As Single, WsRe As Single,

RsWs As Single, WeRe As Single, RsRe As Single

WsRs = TimeDiff(Ws, Rs)

RsWe = TimeDiff(Rs, We)

WsWe = TimeDiff(Ws, We)

WsRe = TimeDiff(Ws, Re)

RsWs = TimeDiff(Rs, Ws)

RsRe = TimeDiff(Rs, Re)

FindCase=0

If WsRs + RsWe = WsWe Then FindCase = FindCase + 1

If RsWs + WsWe + WeRe = RsRe Then FindCase = FindCase + 10

If WsRe + ReWe = WsWe Then FindCase = FindCase + 100

If WsRs + RsRe + ReWe = WsWe Then FindCase = FindCase + 1000

End Function