Re: Newbie: FOR loop on dates



I just tested what I said, apparently if VB sees a number more than 12, it
considers it a month. The default maybe a US date, but it's not clear. I
would rather recommend and use ##. Sample code:

Private Sub Form_Load()
Dim d As Date

d = "5/13/2005"
Debug.Print d
d = "13/5/2005"
Debug.Print d
End Sub

This prints:

5/13/2005
5/13/2005

I am using a US date in the Control Panel. Apparently this could work, but
it's not good if you have team members outside the US, or if you post sample
code on the web.

"Someone" <nobody@xxxxxxx> wrote in message
news:IcIXe.43359$ct5.16749@xxxxxxxxxxxxx
>> d1 = "March 5 1990"
>> d2 = "April 20 1996"
>
> I think VB uses CDate implicitly in this case, so it may generate an error
> in other countries, I don't know. Imagine someone using:
>
> d1 = "5/13/2005" ' May 13 2005
>
> This would generate a runtime error in non-US OS versions. Try "13/5/2005"
> in your computer and see what happens.
>
> Date constants in VB6 are used with ##, for example:
>
> d1 = #5/13/05#
> d1 = #5/13/05 5:00:00 PM#
>
>
>
>
>
> "Mike Williams" <Mike@xxxxxxxxxxxxxxxxx> wrote in message
> news:dgn4ki$7q7$1@xxxxxxxxxxxxxxxxxxxxxx
>> "Newbie" <steve@xxxxxxxx> wrote in message
>> news:CfEXe.797$hW.529@xxxxxxxxxx
>>
>>> Hello, i was wondering if there is a way to loop through
>>> dates. e.g.. I want to loop through all dates between
>>> March 5th,1990 to April 20th,1996.
>>
>> Fortunately Visual Basic is very forgiving on all sorts of stuff. Is this
>> what you want? Paste it into a button click event or something on a Form
>> that contains a ListBox:
>>
>> Dim d1 As Date, d2 As Date, n As Date
>> d1 = "March 5 1990"
>> d2 = "April 20 1996"
>> For n = d1 To d2 Step 1
>> List1.AddItem n
>> Next n
>>
>> Mike
>>
>>
>>
>
>


.