By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,191 Members | 1,067 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,191 IT Pros & Developers. It's quick & easy.

Trying to understand VB

P: n/a
Hello folks,

I found this piece of code on this group by Dorman Blackman:
Function BusinessDays(dDate1, dDate2) As Long
BusinessDays = (DateDiff("d", dDate1, dDate2) - _
(DateDiff("ww", dDate1, dDate2) * 2) + 1) + _
(WeekDay(dDate1) = vbSunday) + _
(WeekDay(dDate2) = vbSaturday)
End Function


It works as well(if not better, i've not tested it on a massive
database) as the other codes that have been posted, but I don't
understand the last two lines.

(WeekDay(dDate1) = vbSunday) and (WeekDay(dDate2) = vbSaturday)

I've not seen any other code that uses similar syntax and to me it
looks like it needs an IF statement, but this obviously returns a
number to be used in the calculation.

I thought about contacting Dorman, but the last posts seem to end about
five/six years ago.

I appreciate any help in understanding this.

SEAN

Apr 28 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi, Sean.
but I don't
understand the last two lines.

(WeekDay(dDate1) = vbSunday) and (WeekDay(dDate2) = vbSaturday)
These are boolean expressions. If dDate1 happens to be a Sunday, then
(WeekDay(dDate1) = vbSunday) will evaluate to TRUE. The equivalent of TRUE
in VB is -1. If dDate1 is not a Sunday, then the expression will evaluate
to FALSE. The equivalent of FALSE in VB is 0.

Therefore, if dDate1 is a Sunday, subtract 1 from the days calculated thus
far. Otherwise, leave the days calculated thus far alone.

Likewise with dDate2. If it's a Saturday, then subtract 1 from the days
calculated thus far. Otherwise, leave the days calculated thus far alone.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/ex...ributors2.html for contact
info.
"badboybrown" <se*****@gmail.com> wrote in message
news:11**********************@y43g2000cwc.googlegr oups.com... Hello folks,

I found this piece of code on this group by Dorman Blackman:
Function BusinessDays(dDate1, dDate2) As Long
BusinessDays = (DateDiff("d", dDate1, dDate2) - _
(DateDiff("ww", dDate1, dDate2) * 2) + 1) + _
(WeekDay(dDate1) = vbSunday) + _
(WeekDay(dDate2) = vbSaturday)
End Function


It works as well(if not better, i've not tested it on a massive
database) as the other codes that have been posted, but I don't
understand the last two lines.

(WeekDay(dDate1) = vbSunday) and (WeekDay(dDate2) = vbSaturday)

I've not seen any other code that uses similar syntax and to me it
looks like it needs an IF statement, but this obviously returns a
number to be used in the calculation.

I thought about contacting Dorman, but the last posts seem to end about
five/six years ago.

I appreciate any help in understanding this.

SEAN

Apr 28 '06 #2

P: n/a
Thank you very much.

I'm going to test it a bit more, but it looks like pretty efficient
code.

SEAN

Apr 28 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.