Date as a for loop control variable

A

Angel

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
 
J

Jon Skeet [C# MVP]

Angel said:
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)
{
....
}
 
M

Morten Wennevik

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))
{
....
}
 
J

Jon Skeet [C# MVP]

Morten Wennevik said:
Except that wouldn't work in C# either :p

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

Whoops. Doh, doh, doh!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top