ok. Heres the thing. I need to make cases for keydowns. I am catching the keycodes and them pass them on to switches. the un-understandable part for me is this:
I have the same case for 'TAB' and 'DOWN' keys. Now, I was wondering if instead of repeating the same code twice, I could use the logical 'OR' operator in cases:

Now:

switch(keycode){
               case DOWN:
                    if(edtIndex == editSize - 1){
                         fieldPos = edtList[0];
                         edtIndex = 0;
                    }
                    else if(edtIndex < editSize - 1)
                         fieldPos = edtList[++edtIndex];
                    break;
               case TAB:
                    if(edtIndex == editSize - 1){
                         fieldPos = edtList[0];
                         edtIndex = 0;
                    }
                    else if(edtIndex < editSize - 1)
                         fieldPos = edtList[++edtIndex];
                    break;
          }

is it possible to do this:

switch(keycode){
               case DOWN || TAB:
                    if(edtIndex == editSize - 1){
                         fieldPos = edtList[0];
                         edtIndex = 0;
                    }
                    else if(edtIndex < editSize - 1)
                         fieldPos = edtList[++edtIndex];
                    break;
          }

Have you tried it? Compile it and see how it goes. Alternatively, you can put the code under one case into a function and call it on both cases.

Have you tried it? Compile it and see how it goes. Alternatively, you can put the code under one case into a function and call it on both cases.

Ok, it did compile, but neither the 'DOWN' nor the 'TAB' were taken as seperate cases. instead, "DOWN || TAB" was taken as a single case. So I think I will have to use multiple codes.

just use two (or more) case statements with no break in between

switch(keycode){
    case DOWN :
    case TAB:
                    if(edtIndex == editSize - 1){
                         fieldPos = edtList[0];
                         edtIndex = 0;
                    }
                    else if(edtIndex < editSize - 1)
                         fieldPos = edtList[++edtIndex];
                    break;
          }
Comments
Marvelous!!
This article has been dead for over six months. Start a new discussion instead.