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;
          }

Recommended Answers

All 3 Replies

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;
          }
commented: Marvelous!! +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.