LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
millsy
 
Posts: n/a
Default UDF's using other UDF's


Is there any problem with using one UDF within another because I am
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


--
millsy
------------------------------------------------------------------------
millsy's Profile: http://www.excelforum.com/member.php...fo&userid=5122
View this thread: http://www.excelforum.com/showthread...hreadid=494261

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:41 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"