Don't call the Add method on the list you are iterating through. What
exactly are you trying to do in the loop? It looks like you are trying to
add an item to the loop with each iteration. But you will never reach the
end of the loop that way.
What is the logic supposed to be here?

Signature
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
> Well how can I resolve this
brandonjack007@gmail.com - 20 Jul 2007 20:17 GMT
public class UserDate : System.Web.UI.WebControls.WebControl
{
System.DateTime dSelectedDate;
System.DateTime dMinDate;
System.DateTime dMaxDate;
System.Int16 dMonth;
System.Int16 dDay;
System.Int16 dYear;
public static System.Collections.ArrayList Get_DaysOfMonth(int
Month, int Year)
{
int iDay;
ArrayList DaysList = new ArrayList();
if (Month >= 1 & Month <= 12)
{
for (iDay = 1; iDay <=
System.DateTime.DaysInMonth(Year, Month); iDay++)
{
DaysList.Add(iDay);
}
}
return DaysList;
}
public static ArrayList Get_DaysOfMonth()
{
int iDay;
ArrayList DaysList = new ArrayList();
for (iDay = 1; iDay <= 31; iDay++)
{
DaysList.Add(iDay);
}
return DaysList;
}
public static ArrayList Get_MonthsOfYear(bool Abbreviate)
{
ArrayList MonthsList = new ArrayList();
int i;
for (i = 1; i <= 12; i++)
{
MonthsList.Add(DateTime.Now.ToString("MMMM"));
}
return MonthsList;
}
public static ArrayList Get_FutureYears()
{
return Get_RecentYears(0, 6);
}
public static ArrayList Get_NextXYears(int nNbrOfYearsForward)
{
return Get_RecentYears(0, nNbrOfYearsForward);
}
public static ArrayList Get_RecentYears()
{
return Get_RecentYears(3, 3);
}
public static ArrayList Get_RecentYears(int nRangeOfYearsBack,
int nRangeOfYearsForward)
{
ArrayList YearsList = new ArrayList();
int i;
for (i = ((System.DateTime.Now.Year) - nRangeOfYearsBack);
i <= ((System.DateTime.Now.Year) + nRangeOfYearsForward); i++)
{
YearsList.Add(i);
}
return YearsList;
}
private string BuildDayDropDown()
{
System.Text.StringBuilder sHtml = new
System.Text.StringBuilder();
ArrayList oDaysList;
int iDay;
sHtml.Append("<select id='" + this.ID + "_Day'>");
oDaysList = Get_DaysOfMonth();
for (iDay = 0; iDay <= oDaysList.Count - 1; iDay++)
{
sHtml.Append("<option value='" + iDay.ToString() +
"'>" + iDay.ToString() + "</option>");
}
sHtml.Append("</select>");
return sHtml.ToString();
}
private string BuildMonthDropDown()
{
System.Text.StringBuilder sHtml = new
System.Text.StringBuilder();
ArrayList oMonthsList;
int iMonth;
sHtml.Append("<select id='" + this.ID + "_Month'>");
oMonthsList = Get_MonthsOfYear(true);
for (iMonth = 0; iMonth <= oMonthsList.Count - 1; iMonth+
+)
{
sHtml.Append("<option value='" + iMonth.ToString() +
"'>" + iMonth + "</option>");
}
sHtml.Append("</select>");
return sHtml.ToString();
}
private string BuildYearDropDown()
{
System.Text.StringBuilder sHtml = new
System.Text.StringBuilder();
ArrayList oYearsList;
int iYear;
sHtml.Append("<select id='" + this.ID + "_Year'>");
oYearsList = Get_RecentYears();
for (iYear = 0; iYear <= oYearsList.Count - 1; iYear++)
{
sHtml.Append("<option value='" + iYear + "'>" + iYear
+ "</option>");
}
sHtml.Append("</select>");
return sHtml.ToString();
}
public string Date
{
get { return dSelectedDate.ToString(); }
set { dSelectedDate = System.Convert.ToDateTime(value); }
}
public string MinDate
{
get { return dMinDate.ToString(); }
set { dMinDate = System.Convert.ToDateTime(value); }
}
public string MaxDate
{
get { return dMaxDate.ToString(); }
set { dMaxDate = System.Convert.ToDateTime(value); }
}
public int Month
{
get { return dMonth; }
set { dMonth = System.Convert.ToInt16(value); }
}
public int Day
{
get { return dDay; }
set { dDay = System.Convert.ToInt16(value); }
}
public int Year
{
get { return dYear; }
set { dYear = System.Convert.ToInt16(value); }
}
protected override void Render(System.Web.UI.HtmlTextWriter
output)
{
System.Text.StringBuilder html = new
System.Text.StringBuilder();
html.Append("<table border='1'><tr><td>");
html.Append(BuildMonthDropDown());
html.Append("</td><td>");
html.Append(BuildDayDropDown());
html.Append("</td><td>");
html.Append(BuildYearDropDown());
html.Append("</td></tr></table>");
output.Write(html.ToString());
}
}
}
Nicholas Paldino [.NET/C# MVP] - 20 Jul 2007 20:28 GMT
Ok, that does absolutely nothing to answer the question I asked.

Signature
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
> public class UserDate : System.Web.UI.WebControls.WebControl
> {
[quoted text clipped - 192 lines]
> }
> }
> Well how can I resolve this
Um. Either stop adding stuff to the list you're using as the termination
condition for your loop, or stop using as the termination condition for
your loop the count of the list you keep adding stuff to.
You might get a better answer if you could explain why it is you feel you
need to add new members to your list each iteration through the loop.
It's hard to say given the code you posted, since neither code example
seems all that useful. Maybe you meant to write something like this
instead:
for (iYear = 0; iYear < oYearsList.Count; iYear++)
{
sHtml.Append("<option value='" + oYearsList[iYear].ToString()
+ "'>" + oYearsList[iYear].ToString() + "</option>");
}
Which simply takes each object in the list, converts it to a string, and
includes the value in your output.
There are other aspects of the code that are troubling, such as the fact
that you're appending what looks like XML to something with "Html" in the
name, the fact that you appear to have redundant information in your
output, and the fact that there's no other formatting to the output (like
indentation and line breaks) that would make the output more readable by
humans (obviously not strictly necessary, but it sacrifices one
significant benefit of using text for data output).
But maybe those are all non-issues. You haven't described what you're
actually doing with enough detail for me or anyone else here to say for
sure those are problems.
Finally, just for completeness, here is a version of your code that
changes the behavior the least, while still fixing the infinite loop:
int cyears = oYearsList.Count;
for (iYear = 0; iYear <= cyears - 1; iYear++)
{
sHtml.Append("<option value='" + oYearsList.Add(iYear)
+ "'>" + oYearsList.Add(iYear) + "</option>");
}
All that does is get the count once, rather than retrieving it each time
through the loop. The rest of the code still looks wrong to me, but
hey...if that's what you really really wanted to do, the above is how to
get it to work as you presumably intended it to.
Pete