Reputation: 65
In the following code snippet, what I intend is on every timer tick event, it should fall in 'next' case of the switch statement. However, as I Run, it goes through Odd cases first and then even cases?
What mistake I am making?
private void timer1_Tick(object sender, EventArgs e)
{
switch (SCROLL_SCREEN_NO)
{
case 0:
SCROLL_SCREEN_NO = 1;
break;
case 1: label1.Text = "Param1";
label2.Text = "1234";
SCROLL_SCREEN_NO = 2;
break;
case 2: label1.Text = "Param2";
label2.Text = "5678";
SCROLL_SCREEN_NO = 3;
break;
case 3: label1.Text = "Param3";
label2.Text = "9012";
SCROLL_SCREEN_NO = 0;
break;
case 4: label1.Text = "Param4";
label2.Text = "0";
SCROLL_SCREEN_NO = 5;
break;
case 5: label1.Text = "Param5";
label2.Text = "02";
SCROLL_SCREEN_NO = 0;
break;
default: { break; }
}
}
Upvotes: 1
Views: 106
Reputation: 2812
your code is really mistakable, try this:
private void timer1_Tick(object sender, EventArgs e)
{
string[] L1Keys = new string[]{"Param1", "Param2","Param3","Param4","Param5"};
string[] L2Keys = new string[]{"1234", "5678","9012","0","02"};
label1.Text = L1Keys[SCROLL_SCREEN_NO];
label2.Text = L2Keys[SCROLL_SCREEN_NO];
if(SCROLL_SCREEN_NO >=0 && SCROLL_SCREEN_NO<=4)
SCROLL_SCREEN_NO = (SCROLL_SCREEN_NO+1) % 5;
}
Upvotes: 2
Reputation: 946
Your code seems to be OK. Are you using SCROLL_SCREEN_NO outside of this timer tick event? If so then please look at the code again that used SCROLL_SCREEN_NO.
Upvotes: 0