I have created a function Response Time as follows:
Public Function responsetime( StartDate As String, EndDate As String) As Double
Dim w As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Dim uidoc As NotesUIDocument
Dim i As Integer, ctr As Integer
Dim dt1 As NotesDateTime
Dim busdays As Variant
Dim no_of_bussdays As Integer
Dim holidaylist (1 To 15) As String
Dim dtEnd As NotesDateTime
Dim dtStart As NotesDateTime
Dim dtTempHoliday As NotesDateTime
Dim lstHolidays List As String
Dim viewIT As NotesView
Dim entry As NotesViewEntry
Dim selString As String
Dim monstart As NotesDateTime
Dim monend As NotesDateTime
Dim monlunchstart As NotesDateTime
Dim monlunchend As NotesDateTime
Dim fristart As NotesDateTime
Dim friend As NotesDateTime
Dim frilunchstart As NotesDateTime
Dim frilunchend As NotesDateTime
Dim starttime As NotesDateTime
Dim endtime As NotesDateTime
Dim lunchstarttime As NotesDateTime
Dim lunchendtime As NotesDateTime
Dim fridays As Variant
Dim no_of_firdays As Integer
Dim time_weekdays As Double
Dim time_fridays As Double
Dim time_startday As Double
Dim time_endday As Double
Set db = session.CurrentDatabase
Set uidoc = w.CurrentDocument
'Getting Timings from “Timings” View*************************************************
Set viewIT = db.GetView("Timings")
selstring = uidoc.FieldgetText("x_fd_location")
Set entry = viewIT.Getentrybykey(selstring)
Set monstart = New NotesDateTime(entry.ColumnValues(1))
Set monend = New NotesDateTime(entry.ColumnValues(2))
Set monlunchstart = New NotesDateTime(entry.ColumnValues(3))
Set monlunchend = New NotesDateTime(entry.ColumnValues(4))
Set fristart = New NotesDateTime(entry.ColumnValues(5))
Set friend = New NotesDateTime(entry.ColumnValues(6))
Set frilunchstart = New NotesDateTime(entry.ColumnValues(7))
Set frilunchend = New NotesDateTime(entry.ColumnValues(8))
'Setting Holidays*****************************************************************
lstHolidays("02/05/2007") = "Kashmir Day"
lstHolidays("03/23/2007") = "Pakistan Day"
lstHolidays("05/01/2007") = "Labor Day"
lstHolidays("08/14/2007") = "Independence Day"
lstHolidays("11/09/2007") = "Iqbal's Day"
lstHolidays("12/25/2007") = "Quaid's Day"
'Calculating time for Business days exculding start date and end date***********************
'Calculating days exclucding sundays and saturdays
Set dtStart = New NotesDateTime(StartDate)
Set dtEnd = New NotesDateTime(EndDate )
busdays = Evaluate({@BusinessDays([ } & Cdat(dtStart.DateOnly) & {]; [} & Cdat(dtEnd.DateOnly) & {]; 1:7)})
no_of_bussdays= Cint(busdays(0))
'Count num of holidays and subtract it from business days
Forall h In lstHolidays
Set dtTempHoliday = New NotesDateTime( Listtag(h) )
If (dtTempHoliday.TimeDifferenceDouble( dtStart ) >= 0) _
And (dtEnd.TimeDifferenceDouble( dtTempHoliday ) >= 0) Then
' Holiday is in this range
no_of_bussdays = no_of_bussdays - 1
End If
End Forall
'Count no of fridays and subtract it from business days as fridays have different timings
fridays = Evaluate({@BusinessDays([ } & Cdat(dtStart.DateOnly) & {]; [} & Cdat(dtEnd.DateOnly) & {]; 1:2:3:4:5:7)})
no_of_fridays = Cint(fridays(0))
’ if user request day is friday then subtract 1 from no of fridays
If(Weekday(dtstart.DateOnly) = 6) Then
no_of_fridays = no_of_fridays-1
End If
’ if IT request day is friday then subtract 1 from no of fridays
If(Weekday(dtend.DateOnly) = 6) Then
no_of_fridays = no_of_fridays-1
End If
’ calculate time for days between start and end date excluding fridays
time_weekdays = (no_of_bussdays - no_of_fridays-2) *( ((Cdat(monend.TimeOnly) - Cdat(monstart.TimeOnly)) - (Cdat(monlunchend.TimeOnly) - Cdat(monlunchstart.TimeOnly))) * 24)
'calculate time for fridays between start and end dates
time_fridays = (no_of_fridays) *( ((Cdat(friend.TimeOnly) - Cdat(fristart.TimeOnly)) - (Cdat(frilunchend.TimeOnly) - Cdat(frilunchstart.TimeOnly))) * 24)
‘calculate time for start day and end day’***********************************************
If(Not(Weekday(dtstart.DateOnly) = 6)) Then
Set starttime = New NotesDateTime(monstart.TimeOnly)
Set endtime = New NotesDateTime(monend.TimeOnly)
Set lunchstarttime = New NotesDateTime(monlunchstart.TimeOnly)
Set lunchendtime = New NotesDateTime(monlunchend.TimeOnly)
Else
Set starttime = New NotesDateTime(fristart.TimeOnly)
Set endtime = New NotesDateTime(friend.TimeOnly)
Set lunchstarttime = New NotesDateTime(frilunchstart.TimeOnly)
Set lunchendtime = New NotesDateTime(frilunchend.TimeOnly)
End If
’ START DAY
’ if start time is less than official start time then add whole day time
If (Cdat(dtstart.TimeOnly)<Cdat(starttime.TimeOnly)) Then
time_startday = (Cdat(starttime.TimeOnly) - Cdat(endtime.TimeOnly)) * 24
Else
’ if start time is greater than official end time then add nothing
If (Cdat(dtstart.TimeOnly)>Cdat(endtime.TimeOnly)) Then
time_startday = 0
Else
’ if start time is between official timings then add calculated time
If( (Cdat(dtstart.TimeOnly) >= Cdat(starttime.TimeOnly)) And ( Cdat(dtstart.TimeOnly)<=Cdat(endtime.TimeOnly) ) ) Then
time_startday = ( Cdat(endtime.TimeOnly) - Cdat(dtstart.TimeOnly) ) * 24
End If
End If
End If
'Call uidoc.FieldSetText(“a”,Cstr(time_startday))
’ subtracting lunch time
’ if start time is between lunch time then subtract the calculated time
If( (Cdat(dtstart.TimeOnly) >= Cdat(lunchstarttime.TimeOnly)) And ( Cdat(dtstart.TimeOnly)<=Cdat(lunchendtime.TimeOnly) ) ) Then
time_startday = time_startday - (( Cdat(lunchendtime.TimeOnly) - Cdat(dtstart.TimeOnly) ) * 24)
’ if start time is before lunch time then subtract whole lunch time
Else
If( Cdat(dtstart.TimeOnly) < Cdat(lunchstarttime.TimeOnly)) Then
time_startday = time_startday - (( Cdat(lunchendtime.TimeOnly) - Cdat(lunchstarttime.TimeOnly) ) * 24)
End If
End If
'END DAY
' if end time is greater than official end time then add whole day time
If (Cdat(dtend.TimeOnly)>Cdat(endtime.TimeOnly)) Then
time_endday = (Cdat(starttime.TimeOnly) - Cdat(endtime.TimeOnly)) * 24
Else
’ if end time is less than official start time then add nothing
If (Cdat(dtend.TimeOnly)<Cdat(starttime.TimeOnly)) Then
time_endday = 0
Else
’ if end time is between official timings then add calculated time
If( (Cdat(dtend.TimeOnly) >= Cdat(starttime.TimeOnly)) And ( Cdat(dtend.TimeOnly)<=Cdat(endtime.TimeOnly) ) ) Then
time_endday = ( Cdat(dtend.TimeOnly) - Cdat(starttime.TimeOnly) ) * 24
End If
End If
End If
’ subtracting lunch time
’ if end time is between lunch time then subtract calculated time
If( (Cdat(dtend.TimeOnly) >= Cdat(lunchstarttime.TimeOnly)) And ( Cdat(dtend.TimeOnly)<=Cdat(lunchendtime.TimeOnly) ) ) Then
time_endday = time_endday - (( Cdat(dtend.TimeOnly) - Cdat(lunchstarttime.TimeOnly) ) * 24)
’ if end time is after lunch time then subtract whole lunch time
Else
If( Cdat(dtend.TimeOnly) > Cdat(lunchendtime.TimeOnly) ) Then
time_endday = time_endday - (( Cdat(lunchendtime.TimeOnly) - Cdat(lunchstarttime.TimeOnly) ) * 24)
End If
End If
’ Return the calculated response time in hours******************************************
responsetime = time_weekdays + time_fridays + time_startday + time_endday
End Function
It works fine if i paste this function in the Globals but when i create a script library for this function and call the function as
i = responsetime (uidoc.FieldGetText(“date1”),uidoc.FieldGetText(“date2”))
then it gives error on this line.
any tips??
Regards,
Aisha Ishrat.