Little Problem with flag variable
avi_dave
Posts: 62
This block of code executes everytime in many different jobs but I cant seem to figure out whats stopping it this time around, can I rewrite this and still end up with the same timing and function
Code:
button_event [dcPhSpdDial]
{
Hold[30]:
{
IF(button.holdtime < 30)
{
HowLong_Phone = 0; //flag dial it
}
Else IF (button.holdtime > 30)
{
HowLong_Phone = 1; //flag go to another page
}
{
switch (button.input.channel)
{
case 21:
{
select
{
active(HowLong_Phone == 0):{SEND_STRING dvBiamp,"'DIAL 1 TIPHONENUM 136 ',cPhoneNumbers[1],$0A"} //Dial it
active(HowLong_Phone == 1):{Send_Command TP1A,'PAGE-Phone Book'} //Phone Book Page
}
}
case 22:
{
select
{
active(HowLong_Phone == 0):{SEND_STRING dvBiamp,"'DIAL 1 TIPHONENUM 136 ',cPhoneNumbers[2],$0A"} //Dial it
active(HowLong_Phone == 1):{Send_Command TP1A,'PAGE-Phone Book'} //Phone Book Page
}
}
case 23:
{
select
{
active(HowLong_Phone == 0):{SEND_STRING dvBiamp,"'DIAL 1 TIPHONENUM 136 ',cPhoneNumbers[3],$0A"} //Dial it
active(HowLong_Phone == 1):{Send_Command TP1A,'PAGE-Phone Book'} //Phone Book Page
}
}
case 24:
{
select
{
active(HowLong_Phone == 0):{SEND_STRING dvBiamp,"'DIAL 1 TIPHONENUM 136 ',cPhoneNumbers[4],$0A"} //Dial it
active(HowLong_Phone == 1):{Send_Command TP1A,'PAGE-Phone Book'} //Phone Book Page
}
}
case 25:
{
select
{
active(HowLong_Phone == 0):{SEND_STRING dvBiamp,"'DIAL 1 TIPHONENUM 136 ',cPhoneNumbers[5],$0A"} //Dial it
active(HowLong_Phone == 1):{Send_Command TP1A,'PAGE-Phone Book'} //Phone Book Page
}
}
case 26:
{
select
{
active(HowLong_Phone == 0):{SEND_STRING dvBiamp,"'DIAL 1 TIPHONENUM 136 ',cPhoneNumbers[6],$0A"} //Dial it
active(HowLong_Phone == 1):{Send_Command TP1A,'PAGE-Phone Book'} //Phone Book Page
}
}
DEFAULT:{HowLong_Phone = 0;}
}
}
}
}
Code:
button_event [dcPhSpdDial]
{
Hold[30]:
{
IF(button.holdtime < 30)
{
HowLong_Phone = 0; //flag dial it
}
Else IF (button.holdtime > 30)
{
HowLong_Phone = 1; //flag go to another page
}
{
switch (button.input.channel)
{
case 21:
{
select
{
active(HowLong_Phone == 0):{SEND_STRING dvBiamp,"'DIAL 1 TIPHONENUM 136 ',cPhoneNumbers[1],$0A"} //Dial it
active(HowLong_Phone == 1):{Send_Command TP1A,'PAGE-Phone Book'} //Phone Book Page
}
}
case 22:
{
select
{
active(HowLong_Phone == 0):{SEND_STRING dvBiamp,"'DIAL 1 TIPHONENUM 136 ',cPhoneNumbers[2],$0A"} //Dial it
active(HowLong_Phone == 1):{Send_Command TP1A,'PAGE-Phone Book'} //Phone Book Page
}
}
case 23:
{
select
{
active(HowLong_Phone == 0):{SEND_STRING dvBiamp,"'DIAL 1 TIPHONENUM 136 ',cPhoneNumbers[3],$0A"} //Dial it
active(HowLong_Phone == 1):{Send_Command TP1A,'PAGE-Phone Book'} //Phone Book Page
}
}
case 24:
{
select
{
active(HowLong_Phone == 0):{SEND_STRING dvBiamp,"'DIAL 1 TIPHONENUM 136 ',cPhoneNumbers[4],$0A"} //Dial it
active(HowLong_Phone == 1):{Send_Command TP1A,'PAGE-Phone Book'} //Phone Book Page
}
}
case 25:
{
select
{
active(HowLong_Phone == 0):{SEND_STRING dvBiamp,"'DIAL 1 TIPHONENUM 136 ',cPhoneNumbers[5],$0A"} //Dial it
active(HowLong_Phone == 1):{Send_Command TP1A,'PAGE-Phone Book'} //Phone Book Page
}
}
case 26:
{
select
{
active(HowLong_Phone == 0):{SEND_STRING dvBiamp,"'DIAL 1 TIPHONENUM 136 ',cPhoneNumbers[6],$0A"} //Dial it
active(HowLong_Phone == 1):{Send_Command TP1A,'PAGE-Phone Book'} //Phone Book Page
}
}
DEFAULT:{HowLong_Phone = 0;}
}
}
}
}
0
Comments
So, your flag variable in the code you wrote will always = 1.
This is what I would suggest:
perhaps you could simplify the hold event handler code if it always does the same thing when one of the buttons is held for more than 3.0 seconds.
Also, the way that you have written your code suggests that you might be able to simplify the release: code
(Uncompiled and untested)
Your approach works fine although my instinct would be to do it like this: