PC Review


Reply
Thread Tools Rate Thread

Date as a for loop control variable

 
 
Angel
Guest
Posts: n/a
 
      22nd Jun 2004
Hi,

Can someone let me know how we can have a for loop where
the date is incremented without using date as the control
variable as hown below.

dim varDate as Date
For varDate = StartDate + 1 To EndDate - 1
Next varDate

the above stmt is no longer supported in .NET

thanks
angel
 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      22nd Jun 2004
Angel <(E-Mail Removed)> wrote:
> Can someone let me know how we can have a for loop where
> the date is incremented without using date as the control
> variable as hown below.
>
> dim varDate as Date
> For varDate = StartDate + 1 To EndDate - 1
> Next varDate
>
> the above stmt is no longer supported in .NET


If you want to do it in VB.NET, I'm not sure - you *might* need to use
a Do/While loop instead.

In C# you could do something like:

for (DateTime foo = StartDate; foo=foo.AddDays(1); foo < EndDate)
{
....
}

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
Morten Wennevik
Guest
Posts: n/a
 
      22nd Jun 2004
> for (DateTime foo = StartDate; foo=foo.AddDays(1); foo < EndDate)
> {
> ...
> }
>


Except that wouldn't work in C# either :P

for(DateTime foo = StartDate; foo < EndDate; foo = foo.AddDays(1))
{
....
}

--
Happy coding!
Morten Wennevik [C# MVP]
 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      22nd Jun 2004
Morten Wennevik <(E-Mail Removed)> wrote:
> > for (DateTime foo = StartDate; foo=foo.AddDays(1); foo < EndDate)
> > {
> > ...
> > }
> >

>
> Except that wouldn't work in C# either :P
>
> for(DateTime foo = StartDate; foo < EndDate; foo = foo.AddDays(1))
> {
> ...
> }


Whoops. Doh, doh, doh!

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
Uri Dor
Guest
Posts: n/a
 
      23rd Jun 2004
for(DateTime time=DateTime.Now; time<DateTime.Now.AddDays(50);
time.AddDays(1)) {}


Angel wrote:
> Hi,
>
> Can someone let me know how we can have a for loop where
> the date is incremented without using date as the control
> variable as hown below.
>
> dim varDate as Date
> For varDate = StartDate + 1 To EndDate - 1
> Next varDate
>
> the above stmt is no longer supported in .NET
>
> thanks
> angel

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing a Date Variable from Code to Update Query in a Loop MJ Microsoft Access 7 27th Dec 2007 09:39 PM
Re: For loop variable date Herfried K. Wagner [MVP] Microsoft VB .NET 4 2nd Dec 2006 07:19 PM
Re: For loop variable date Cor Ligthert [MVP] Microsoft VB .NET 0 2nd Dec 2006 04:28 AM
2 ITEMS: Set control/object variable and Get date info =?Utf-8?B?TW9uYS1BQkU=?= Microsoft Access VBA Modules 2 31st May 2006 04:34 PM
Is it possible to use date as a for loop control variable ? Microsoft Dot NET 1 22nd Jun 2004 03:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:21 PM.