Home > ASP Development > ASP date loop out of memory

ASP date loop out of memory



I have a problem with a bit of asp used in a date selection box.



It is supposed to get the right days and dates and then list them in the select box for up to a week ahead. The error i get is Out Of Memory specifically the line reading:

ReDim daysOfWeek(strDaysTaken)



Here is the code:




Code:



<select name="date">
<option value="<%=Year(Date) & "-" & Month(Date) & "-" & Day(Date)%>">Today</option>
<option value="<%=Year(DateAdd("d", 1,(Date))) & "-" & Month(DateAdd("d", 1,(Date))) & "-" & Day(DateAdd("d", 1,(Date)))%>">Tomorrow</option>
<%
startDate = Day(DateAdd("d", 2,(Date))) & " " & MonthName(Month(DateAdd("d", 2,(Date)))) & ", " & Year(DateAdd("d", 2,(Date)))
endDate = Day(DateAdd("d", 7,(Date))) & " " & MonthName(Month(DateAdd("d", 4,(Date)))) & ", " & Year(DateAdd("d", 4,(Date)))

strDaysTaken=DateDiff("d", startDate, endDate)
strDays=strDaysTaken

i=0
temp1 = 0
ReDim daysOfWeek(strDaysTaken)
ReDim datesOfWeek(strDaysTaken)
do while temp1<= strDays
temp2 = weekdayname(weekday(DateAdd("d", temp1, startDate))) & ", " & day(DateAdd("d", temp1, startDate)) & " " & MonthName(Month((DateAdd("d", temp1, startDate))),true)
temp3 = Year(DateAdd("d", temp1, startDate)) & "-" & Month(DateAdd("d", temp1, startDate)) & "-" & day(DateAdd("d", temp1, startDate))
daysOfWeek(i)= temp2
datesOfWeek(i) = temp3
%>
<option value="<%=datesOfWeek(i)%>"><%=daysOfWeek(i)%></option>
<%
i=i+1
temp1=temp1+1
loop
%>
</select>






Any help would be really appreciated.



Thanks.

    
Guest


Its because you end up with a negative number



replace


Code:



startDate = Day(DateAdd("d", 2,(Date))) & " " & MonthName(Month(DateAdd("d", 2,(Date)))) & ", " & Year(DateAdd("d", 2,(Date)))
endDate = Day(DateAdd("d", 7,(Date))) & " " & MonthName(Month(DateAdd("d", 4,(Date)))) & ", " & Year(DateAdd("d", 4,(Date)))






with




Code:



startDate = DateAdd("d", 2,(Date))
endDate = DateAdd("d", 7,(Date))



Was this answer helpful ? Yes No   
Guest


perfect! thanks.

Was this answer helpful ? Yes No   
Guest
 
 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2008 by Infoqu. All rights reserved