Date as a for loop control variable

  • Thread starter Thread starter Angel
  • Start date Start date
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
 
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)
{
....
}
 
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))
{
....
}
 
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!
 
Back
Top