Home All Groups Group Topic Archive Search About

For loop variable date

Author
1 Dec 2006 8:49 PM
martin1
Hi, all,

I try to use Date as For Loop variable, but it said date cannot be used to
For Loop vaiable, anyone has any iead?

Thanks,
Martin1

Author
1 Dec 2006 8:55 PM
Herfried K. Wagner [MVP]
"martin1" <mart***@discussions.microsoft.com> schrieb:
> I try to use Date as For Loop variable, but it said date cannot be used to
> For Loop vaiable, anyone has any iead?

\\\
Dim StartDate As Date = ...
Dim EndDate As Date = ...
Dim DaysCount As Integer = (EndDate - StartDate).TotalDays
Dim CurrentDate As Date = StartDate
For i As Integer = 1 To DaysCount
    ...
    CurrentDate = CurrentDate.AddDays(1)
Next i
///

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
1 Dec 2006 10:27 PM
martin1
Thank you. Wagner!

Show quoteHide quote
"Herfried K. Wagner [MVP]" wrote:

> "martin1" <mart***@discussions.microsoft.com> schrieb:
> > I try to use Date as For Loop variable, but it said date cannot be used to
> > For Loop vaiable, anyone has any iead?
>
> \\\
> Dim StartDate As Date = ...
> Dim EndDate As Date = ...
> Dim DaysCount As Integer = (EndDate - StartDate).TotalDays
> Dim CurrentDate As Date = StartDate
> For i As Integer = 1 To DaysCount
>     ...
>     CurrentDate = CurrentDate.AddDays(1)
> Next i
> ///
>
> --
>  M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
>  V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
>
>
Author
2 Dec 2006 4:23 AM
Cor Ligthert [MVP]
As Armin has written to you already in past.

Put on Option Strict in top of your program.

Beside that do I not see the purpose of your construction.

Cor

Show quoteHide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> schreef in bericht
news:udMh5rYFHHA.420@TK2MSFTNGP06.phx.gbl...
> "martin1" <mart***@discussions.microsoft.com> schrieb:
>> I try to use Date as For Loop variable, but it said date cannot be used
>> to
>> For Loop vaiable, anyone has any iead?
>
> \\\
> Dim StartDate As Date = ...
> Dim EndDate As Date = ...
> Dim DaysCount As Integer = (EndDate - StartDate).TotalDays
> Dim CurrentDate As Date = StartDate
> For i As Integer = 1 To DaysCount
>    ...
>    CurrentDate = CurrentDate.AddDays(1)
> Next i
> ///
>
> --
> M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
> V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
2 Dec 2006 2:07 PM
Herfried K. Wagner [MVP]
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schrieb:
> As Armin has written to you already in past.
>
> Put on Option Strict in top of your program.

Well, I have not tested the snippet.  Simply replace 'TotalDays' with
'Days'.

> Beside that do I not see the purpose of your construction.

Huh?  Re-read the OP's question and check out his reply to my answer.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
2 Dec 2006 3:49 PM
Cor Ligthert [MVP]
Wagner wrote:
> Huh?  Re-read the OP's question and check out his reply to my answer.

Yes I did already the OP was asking.

> I try to use Date as For Loop variable

You give back an answer with an integer variable.

I would as well be shocked and give back a reply with.

>Thank you. Wagner!

If I was really glad with your answer I would write.

Thank you Herfried.

Cor

Show quoteHide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> schreef in bericht
news:ed4gyshFHHA.3304@TK2MSFTNGP05.phx.gbl...
> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schrieb:
>> As Armin has written to you already in past.
>>
>> Put on Option Strict in top of your program.
>
> Well, I have not tested the snippet.  Simply replace 'TotalDays' with
> 'Days'.
>
>> Beside that do I not see the purpose of your construction.
>
> Huh?  Re-read the OP's question and check out his reply to my answer.
>
> --
> M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
> V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
2 Dec 2006 7:19 PM
Herfried K. Wagner [MVP]
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schrieb:
>> I try to use Date as For Loop variable
>
> You give back an answer with an integer variable.

Well, think why...

> I would as well be shocked and give back a reply with.
>
>>Thank you. Wagner!
>
> If I was really glad with your answer I would write.
>
> Thank you Herfried.

You know that "Herfried" is my first name.  This may be different in the
culture the OP is coming from.


--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
2 Dec 2006 4:28 AM
Cor Ligthert [MVP]
Martin,

In my idea no problem, but keep in mind date datetime is not a collection of
dates. It is just a structure with in it a property ticks that starts at the
beginning of a virtual start of the gregorian calendar (the exact point does
not exist because that calendar is created after that point).

However to do what you say is easy.

\\\
Dim dates() As DateTime = {Now, Now.AddDays(10), Now.AddDays(20)}
        For Each dtm As DateTime In dates
            MessageBox.Show(dtm.ToString)
Next
///

I hope this helps,

Cor


Show quoteHide quote
"martin1" <mart***@discussions.microsoft.com> schreef in bericht
news:FA08F9A6-2F4A-4913-BA08-E08091403B58@microsoft.com...
> Hi, all,
>
> I try to use Date as For Loop variable, but it said date cannot be used to
> For Loop vaiable, anyone has any iead?
>
> Thanks,
> Martin1