Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

loop around dates 1

Status
Not open for further replies.

EricBonsu

MIS
Jul 19, 2006
17
US
I am trying to loop around two dates but get an error message when I use a for loop. Is there a where to loop around two dates to get a string array of the month and year between the two date
 
Any relevant code? Perhaps an error message? Otherwise, you're not likely to get much useful assistance.

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
Here is the error
'For' loop control variable cannot be of type 'Date'.

Here is the code

Dim TheDate as date
Dim ThisMonth, MonthYear, x as String
Dim arrayMonthYear(0) as string

For TheDate = FirstMonthDate To LastMonthDate
Select Case Month(TheDate)
Case 1: ThisMonth ="Jan"
Case 2: ThisMonth ="Feb"
Case 3: ThisMonth ="Mar"
Case 4: ThisMonth ="Apr"
Case 5: ThisMonth ="May"
Case 6: ThisMonth ="Jun"
Case 7: ThisMonth ="Jul"
Case 8: ThisMonth ="Aug"
Case 9: ThisMonth ="Sep"
Case 10: ThisMonth ="Oct"
Case 11: ThisMonth ="Nov"
Case 12: ThisMonth ="Dec"
End Select

MonthYear = ThisMonth
If x = 0 Then
arrayMonthYear(x)= MonthYear
x = x + 1
Else
If MonthYear <> arrayMonthYear(x - 1) Then
ReDim Preserve arrayMonthYear(x)
arrayMonthYear(x) = MonthYear
x = x + 1
End If
End If
Next
 
To be honest there's an awful lot wrong with that code and you would be best off starting from scratch. Can you explain exactly what you are trying to do along with example input and output?


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
OK.
Input is from a form where a user would enter two dates, begin date and end date.
The code would then get the month and year between those dates and put them into an array.
for example if they entered 1/1/07 to 3/1/07 the array should be {Jan07, Feb07, Mar07}

The reason for the array is because it will be use to input into a third party tool to generate charts, so all I need to figure out is how to get that array after someone enter two dates

Thanks for all the help, as you can tell this is new to me.
 
How about something like this?
Code:
Dim d1 as Date = CDate("2007-01-01")
Dim d2 as Date = CDate("2007-03-01")
Dim arrResults as ArrayList

While d1 <= d2
    arrResults.Add(d1.ToString("MMM") & d1.ToString("yy"))
    d1 = d1.AddMonths(1)
End While
I've not tested this but I think it should work.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
Thanks ca8msm it worked perfectly, only thing I had to change was from
Dim arrResults as ArrayList to
Dim arrResults as New ArrayList()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top