yet another array question
here it is
char phone_num[20]
integer count
Define Start
count =1
Define Event
button_event[TP,1]
.
.
.
.
button_event[TP,10]
{
push:
{
if(button.input.channel==10)
phone_num[count]='0'
else
phone_num[count]=itoa(button.input.channel)
count++
}
}
Im trying to save the phone # the users enters in a char array. I just don't understand why even if I set the size of my array to 20, I can't populate individual cells. While debugging array constantly remains empty.
char phone_num[20]
integer count
Define Start
count =1
Define Event
button_event[TP,1]
.
.
.
.
button_event[TP,10]
{
push:
{
if(button.input.channel==10)
phone_num[count]='0'
else
phone_num[count]=itoa(button.input.channel)
count++
}
}
Im trying to save the phone # the users enters in a char array. I just don't understand why even if I set the size of my array to 20, I can't populate individual cells. While debugging array constantly remains empty.
0
Comments
DEFINE_CONSTANT INTEGER TeleButtons[] = {1,2,3,4,5,6,7,8,9,10} //digits starting at 1 and ending at 0 DEFINE_VARIABLE VOLATILE CHAR phone_num[20] VOLATILE CHAR phone_num2[20] VOLATILE INTEGER count = 1 DEFINE_EVENT button_event[TP,TeleButtons] { push:{ STACK_VAR INTEGER nBTN; nBTN = GET_LAST(TeleButtons); phone_num[count]=TYPE_CAST(ITOA(nBTN%10)); phone_num2[count]=GET_BUFFER_CHAR(ITOA(nBTN%10)); SET_LENGTH_ARRAY(phone_num,count); SET_LENGTH_ARRAY(phone_num2,count); IF(count >19) count = 1 ELSE count++ } }I just tested the above code and it seems to work fine. It is displaying properly in the debug window using Emulate device button pushes. I handled the char conversion in two different ways, choose the one you like best
Jeff
button_event[TP,10] { push: { if(button.input.channel==10) phone_num[count]='0' else { phone_num[count]=itoa(button.input.channel) count++ } } }IF and ELSE statements need brackets if you want more than one thing to happen in the IF/ELSE.I think the count should increase every time to allow the 0 digit to be entered. The only problem is that count is going to eventually be larger than the array and will just throw INDEX too large at line xxx errors.
Jeff
DEFINE_VARIABLE VOLATILE CHAR VTC_DIAL_STRING[25] VOLATILE DEVCHAN dcMANUALDIAL[] = { {dvModeroTP, 120}, //KEYPAD # 0 {dvModeroTP, 121}, //KEYPAD # 1 {dvModeroTP, 122}, //KEYPAD # 2 {dvModeroTP, 123}, //KEYPAD # 3 {dvModeroTP, 124}, //KEYPAD # 4 {dvModeroTP, 125}, //KEYPAD # 5 {dvModeroTP, 126}, //KEYPAD # 6 {dvModeroTP, 127}, //KEYPAD # 7 {dvModeroTP, 128}, //KEYPAD # 8 {dvModeroTP, 129}, //KEYPAD # 9 {dvModeroTP, 130}, //KEYPAD . {dvModeroTP, 131} //KEYPAD * } DEFINE_EVENT BUTTON_EVENT[dcMANUALDIAL] { PUSH: { Stack_Var Integer nIndex; Stack_Var Char cDigit[1]; To[Button.Input]; nIndex = Get_Last(dcMANUALDIAL); SELECT { // Numbers 0-9 ACTIVE (nIndex <= 10): cDigit = ITOA(nIndex-1); // Period (.) pressed ACTIVE (nIndex == 11): cDigit = '.'; // Star (*) pressed ACTIVE (nIndex == 12): cDigit = '*'; } VTC_DIAL_STRING = "VTC_DIAL_STRING,cDigit"; SEND_COMMAND Button.Input.Device,"'!T',250,VTC_DIAL_STRING"; } } BUTTON_EVENT[dvModeroTP,132] // CLEAR MANUAL ENTRY { PUSH: { } RELEASE: { VTC_DIAL_STRING = "'"; SEND_COMMAND Button.Input.Device,"'!T',250,VTC_DIAL_STRING"; } } BUTTON_EVENT[dvModeroTP,133] // BACKSPACE MANUAL ENTRY { PUSH: { IF (LENGTH_STRING(VTC_DIAL_STRING)) { TO[BUTTON.INPUT] SET_LENGTH_STRING(VTC_DIAL_STRING,LENGTH_STRING(VTC_DIAL_STRING)-1) SEND_COMMAND BUTTON.INPUT.DEVICE,"'!T',250,VTC_DIAL_STRING" } } }Really appreciate, and so fast as well ..