Ok, so I am biting the bullet and creating my own recurrence patterns. I am
stuck on the loop for a weekly recurrence where multiple days are selected
(i.e. Sunday, Wed, Thur). I have a start date and an end date so I know how
many times to loop, but I can't figure out how to handle the days. So if
the days selected are Sunday and Thursday and the start date is 10/14/08 and
end date is 10/31/08 the end pattern should be Thursday 10/16/08, Sunday
10/19/08, Thursday 10/23/08, Sunday 10/26/08, and Thursday 10/30/08.

Any suggestions are appreciated.

WB

Re: Recurrence loop in VB6 - weekly portion by Steve

Steve
Tue Oct 14 21:11:20 CDT 2008

WB wrote:
> Ok, so I am biting the bullet and creating my own recurrence
> patterns. I am stuck on the loop for a weekly recurrence where
> multiple days are selected (i.e. Sunday, Wed, Thur). I have a start
> date and an end date so I know how many times to loop, but I can't
> figure out how to handle the days. So if the days selected are
> Sunday and Thursday and the start date is 10/14/08 and end date is
> 10/31/08 the end pattern should be Thursday 10/16/08, Sunday
> 10/19/08, Thursday 10/23/08, Sunday 10/26/08, and Thursday 10/30/08.
>
> Any suggestions are appreciated.
>
> WB

I would not hesitate to run a loop through every day from start to finish,
picking out the desired days by the WeekDay function. It will be plenty fast
enough. I have no idea what form you want to pass in the dates or weekdays, or
to get the result, so I just picked some things in this example:

Dim start As Date
Dim finish As Date
Dim test As Date
Dim day As Long
Dim doDays(1 To 7) As Boolean
Dim result As Collection

Set result = New Collection

start = DateSerial(2008, 10, 14)
finish = DateSerial(2008, 10, 31)

doDays(vbSunday) = True
doDays(vbThursday) = True

For test = start To finish
day = Weekday(test)
If doDays(day) Then
result.Add test
End If
Next test

Dim v As Variant
For Each v In result
Debug.Print CDate(v), WeekdayName(Weekday(CDate(v)))
Next v

End Sub



Re: Recurrence loop in VB6 - weekly portion by Larry

Larry
Wed Oct 15 06:52:31 CDT 2008


"WB" <none> wrote in message news:ur9wvImLJHA.4772@TK2MSFTNGP03.phx.gbl...
> Ok, so I am biting the bullet and creating my own recurrence patterns. I am
> stuck on the loop for a weekly recurrence where multiple days are selected
> (i.e. Sunday, Wed, Thur). I have a start date and an end date so I know how
> many times to loop, but I can't figure out how to handle the days. So if
> the days selected are Sunday and Thursday and the start date is 10/14/08 and
> end date is 10/31/08 the end pattern should be Thursday 10/16/08, Sunday
> 10/19/08, Thursday 10/23/08, Sunday 10/26/08, and Thursday 10/30/08.
>
> Any suggestions are appreciated.


See if this gets you farther along...

LFS

Dim weekly(1 To 7) As Boolean
Dim today As Date

'Sunday, Thursday
Erase weekly
weekly(vbSunday) = True
weekly(vbThursday) = True

For today = DateSerial(2008, 10, 14) To DateSerial(2008, 10, 31)
If weekly(WeekDay(today)) Then
Debug.Print Format$(today, "dddd mm/dd/yyyy")
End If
Next



Re: Recurrence loop in VB6 - weekly portion by Saga

Saga
Wed Oct 15 09:38:08 CDT 2008

Instead of

> For today = DateSerial(2008, 10, 14) To DateSerial(2008, 10, 31)

could it also be expressed like so?

> For today = #10/14/2008# To #10/31/2008#

Saga
--

"Larry Serflaten" <serflaten@usinternet.com> wrote in message
news:eV8kuxrLJHA.1160@TK2MSFTNGP04.phx.gbl...
>
> "WB" <none> wrote in message news:ur9wvImLJHA.4772@TK2MSFTNGP03.phx.gbl...
>> Ok, so I am biting the bullet and creating my own recurrence patterns. I am
>> stuck on the loop for a weekly recurrence where multiple days are selected
>> (i.e. Sunday, Wed, Thur). I have a start date and an end date so I know how
>> many times to loop, but I can't figure out how to handle the days. So if
>> the days selected are Sunday and Thursday and the start date is 10/14/08 and
>> end date is 10/31/08 the end pattern should be Thursday 10/16/08, Sunday
>> 10/19/08, Thursday 10/23/08, Sunday 10/26/08, and Thursday 10/30/08.
>>
>> Any suggestions are appreciated.
>
>
> See if this gets you farther along...
>
> LFS
>
> Dim weekly(1 To 7) As Boolean
> Dim today As Date
>
> 'Sunday, Thursday
> Erase weekly
> weekly(vbSunday) = True
> weekly(vbThursday) = True
>
> For today = DateSerial(2008, 10, 14) To DateSerial(2008, 10, 31)
> If weekly(WeekDay(today)) Then
> Debug.Print Format$(today, "dddd mm/dd/yyyy")
> End If
> Next
>
>



Re: Recurrence loop in VB6 - weekly portion by w

w
Wed Oct 15 10:34:12 CDT 2008

My gut instinct was to loop each day, but I thought it would be to
slow....You know they preach about performance in school so much and O^no
and all that. Thanks for the reinforcement.

WB

"Steve Gerrard" <mynamehere@comcast.net> wrote in message
news:U5-dneDwuejVzGjVnZ2dnUVZ_j6dnZ2d@comcast.com...
> WB wrote:
>> Ok, so I am biting the bullet and creating my own recurrence
>> patterns. I am stuck on the loop for a weekly recurrence where
>> multiple days are selected (i.e. Sunday, Wed, Thur). I have a start
>> date and an end date so I know how many times to loop, but I can't
>> figure out how to handle the days. So if the days selected are
>> Sunday and Thursday and the start date is 10/14/08 and end date is
>> 10/31/08 the end pattern should be Thursday 10/16/08, Sunday
>> 10/19/08, Thursday 10/23/08, Sunday 10/26/08, and Thursday 10/30/08.
>>
>> Any suggestions are appreciated.
>>
>> WB
>
> I would not hesitate to run a loop through every day from start to finish,
> picking out the desired days by the WeekDay function. It will be plenty
> fast enough. I have no idea what form you want to pass in the dates or
> weekdays, or to get the result, so I just picked some things in this
> example:
>
> Dim start As Date
> Dim finish As Date
> Dim test As Date
> Dim day As Long
> Dim doDays(1 To 7) As Boolean
> Dim result As Collection
>
> Set result = New Collection
>
> start = DateSerial(2008, 10, 14)
> finish = DateSerial(2008, 10, 31)
>
> doDays(vbSunday) = True
> doDays(vbThursday) = True
>
> For test = start To finish
> day = Weekday(test)
> If doDays(day) Then
> result.Add test
> End If
> Next test
>
> Dim v As Variant
> For Each v In result
> Debug.Print CDate(v), WeekdayName(Weekday(CDate(v)))
> Next v
>
> End Sub
>
>


Re: Recurrence loop in VB6 - weekly portion by Larry

Larry
Wed Oct 15 11:04:30 CDT 2008


"Saga" <antiSpam@somewhere.com> wrote
> Instead of
>
> > For today = DateSerial(2008, 10, 14) To DateSerial(2008, 10, 31)
>
> could it also be expressed like so?
>
> > For today = #10/14/2008# To #10/31/2008#

I thought about using those, which would work in that case, but
date literals are locale specific. DateSerial always produces the
correct value for the supplied input, regardless of locale.

LFS



Re: Recurrence loop in VB6 - weekly portion by Bob

Bob
Wed Oct 15 11:11:57 CDT 2008


"Larry Serflaten" <serflaten@usinternet.com> wrote in message
news:ezv3i%23tLJHA.5232@TK2MSFTNGP02.phx.gbl...
>
> "Saga" <antiSpam@somewhere.com> wrote
>> Instead of
>>
>> > For today = DateSerial(2008, 10, 14) To DateSerial(2008, 10, 31)
>>
>> could it also be expressed like so?
>>
>> > For today = #10/14/2008# To #10/31/2008#
>
> I thought about using those, which would work in that case, but
> date literals are locale specific.

That is incorrect. The #date# format is ALWAYS #mm/dd/yyyy#

Using CDate("10/12/2008") would be a potential problem but using
#10/12/2008# would not

That said, I wouldn't use them in a for/next loop since that's relying on
the specific way VB6 stores the values and I generally try to avoid that
kind of coding. It doesn't rise to the "Select Case True" level (<g>) but
would cause a double-take if I saw it.


> DateSerial always produces the
> correct value for the supplied input, regardless of locale.


Re: Recurrence loop in VB6 - weekly portion by Larry

Larry
Wed Oct 15 14:03:09 CDT 2008


"Bob Butler" <noway@nospam.ever> wrote

> > I thought about using those, which would work in that case, but
> > date literals are locale specific.
>
> That is incorrect. The #date# format is ALWAYS #mm/dd/yyyy#

Yep, I stand corrected. What I wanted to say was that in some
locales where the format is mm/dd/yyyy, using a date literal could
cause a problem. The person entering the code might use their local
format, which, (if not mm/dd/yyyy) would yield incorrect results.

And, seeing Steve's reply using DateSerial, I decided to use that
to reenforce the suggestion to use that function.

Unfortunately, trying to keep the explaination short made for a
completely erroneous statement. Thanks for correcting that!

LFS





Re: Recurrence loop in VB6 - weekly portion by Steve

Steve
Wed Oct 15 20:50:19 CDT 2008

w wrote:
> My gut instinct was to loop each day, but I thought it would be to
> slow....You know they preach about performance in school so much and
> O^no and all that. Thanks for the reinforcement.
>
> WB
>

Understandable. The thing is that math, especially simple loops, goes really
fast. It is all the resources, I/O, screen painting, and such that take all the
time. That loop will determine that there have so far been 199,191 Thursdays and
Sundays since Jan 1, 100, after checking all 697,170 days from then till now.
(That is the dawn of time in VB6, and about the time the Romans built the
Coliseum). If you don't save the dates, and just count them, it takes less than
a second to run, even in the IDE. Compiled it would be even faster.