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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with C# Program

Status
Not open for further replies.

surovi99

IS-IT--Management
Feb 11, 2005
28
US
Hi,

I am trying to generate a random number in a listbox (client_list) on a Windows form. For this I have included a timer control. The program runs but does not show any output. I have set Enabled property of the timer control to True and set the interval to 5 and set the events property to timerprices_Tick. Could someone help me out?

private void timerprices_Tick(object sender,
System.EventArgs e)
{
int counter = 0;
Random r = new Random();

if (counter < 3)
{
String stprices_list =
r.Next(0,200).ToString("000");
client_list.Items.Add(stprices_list);
counter = counter + 1;

}
else
{
timerprices.Enabled = false;
counter = 0;

}
}

Thanks a lot
 
take int counter = 0; out of that method and put it at the top of your class.

int counter is currently a variable local to that method only, not to your class...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top