Hi all,

I am trying to account for business days when calculating an array of date3 which is an array of dates between date1 and date2.

I am aware of @businessday function and I am able to calculate the business days but I will need to incorporate this in my lotusscript. Basically, if a user has the excludeweekend field on form ticked I want to invoke a date calculation without the weekend, else calculate it normally which is the script that I currently have.

For example,

'small portion of script

date1= doc.startdate(0)
date2= doc.enddate(0)

interval= doc.Interval(0)

date1= date1 + interval

n= Cint((date2-date1)/interval)

If n>=0 Then
Redim dates(n) As Variant
i= 0
Do While date1<=date2
dates(i)= Cdat(date1)
i= i + 1
date1= date1 + interval
Loop

If doc.date3(0) = "" Then
doc.date3 = dates

End If
End If

###### Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x

Groupware ConsultantCommented:
Function MoveToNextBusinessDay(d As Variant) As Variant
Dim d2 As Variant

Select Case Weekday(d2)
Case 1
d2= d+1
Case 7
d2= d+2
Case Else
d2= d
End Select
End Function

Just a hunch: the testers won't be happy with the planning resulting from this code...
0

Groupware ConsultantCommented:
'small portion of script

date1= doc.startdate(0)
date2= doc.enddate(0)

interval= doc.Interval(0)

date1= date1 + interval

n= Cint((date2-date1)/interval)

If n>=0 Then
Redim dates(n) As Variant
i= 0
Do While date1<=date2
i= i + 1
date1= date1 + interval
Loop

If doc.date3(0) = "" Then
doc.date3 = dates

End If
End If

and define a function

Function MoveToNextBusinessDay(d As Variant)
...
...
End Function
0

Author Commented:
Could move to MovetoNextBusinessday be something simple like the following?

Function MoveToNextBusinessDay (thisDate As Variant) As Integer

thisDateVar = Datevalue(Cdat(date1))

If (Weekday(thisDateVar) = 1) Or (Weekday(thisDateVar) = 7) Then
Else

End If
Exit Function

End Function
0

Groupware ConsultantCommented:
Naaah, it is simple, but it is supposed to return a date value. Why do difficult if it can be simple. It will return the same day if it's a weekday, the next day (when Sunday) or two days later (when the parameter d is a Saturday).
0

Author Commented:
OK, let's try again, I have to get this right.
Do we have to define a function, can't we for example do something similar to modifications below. I am sure it isn't correct, but tell me if it can be done and i can try to work around it.....

Dim session As New notessession
Dim uiworkspace As New notesuiworkspace
Dim db As notesdatabase
Set db = session.currentdatabase
Dim uidoc As notesuidocument
Dim doc As notesdocument
Set uidoc = uiworkspace.CurrentDocument
Set doc = uidoc.document

Dim d1 As Variant
Dim d2 As Variant

Dim interval As Integer
Dim dates() As Variant
Dim i As Integer
Dim n As Integer

d1= doc.startdate(0)
d2= doc.enddate(0)

interval= doc.Interval(0)
d1= d1 + interval
n= Cint((d2-d1)/interval)

If n>=0  & excludeweekend = "N" Then
Redim dates(n) As Variant
i= 0
Do While d1<=d2
If (Weekday(d1) = 1) Or (Weekday(d) = 7) Then

dates(i)= Cdat(d1 + 1)
i = i + 1
d1= d1 + interval
else
dates(i) = Cdat(d1)
i = i + 1
d1= d1 + interval
Loop

If doc.resultsdate(0) = "" Then
doc.resultsdate = dates

End If
End If

0

Author Commented:

Just a hunch: the testers won't be happy with the planning resulting from this code...

Why exactly?
0

Author Commented:
sjef, I am posting this other code so you can check it out.
It is a function that I requested in regards to difference between two arrays, but i think you guys didn't understand exactly what I am trying to get at.
I'll post it in another question, could you pls take a quick look.

0

Author Commented:
Just a hunch: the testers won't be happy with the planning resulting from this code...

Do you mean because they'll perform less tests for the year because of the weekend exclusion?

0

Groupware ConsultantCommented:
And didn't you have a similar function in one of your earlier questions??

Yes, you could put everything in one module. But what's the point? Instead of a fine function that you can give a meaningful name you now have some meaningless code inside the first module. If that suits you, fine with me :)

WHy they won't be happy? They have to do, statistically speaking, three times more tests on Monday than on any other day!
0

Author Commented:
Re: happy testers

dah!!I am glad the reason wasn't technical. I have enough problems to deal with.

Thanks sjef, as always, your help in much appreciated.
0