Link to home
Start Free TrialLog in
Avatar of sambha03
sambha03

asked on

Need help with case statement

I need to do 2 things with case and was wondering how. First suppose a case is true , how can I exit from it and resume evaluating the next case or goto the default case (case else)?

E.g I need to do something like:
case vbkeyA
  if (DoNotHandleA=TRUE) then Proceed to default case.

I also need to do something like as follows in the keydown event and was wondering if its possible:

 Case (KeyCode = 191) And (Shift = 1)

When I try the above code vb always evaluates the case statement to true and executes the code in it irrespective of the condition.
Avatar of JohnMcCann
JohnMcCann

dim bHandled as boolean

Select case KeyCode:
    Case vbKeyA:
       if Shift = 1 then
          'Do something
          bHandled =true
       End if
    case Else:
       'Do nothing pick it up later
End select

if not bHandled then
   'Do default
end if
Or

Select case KeyCode:
   Case vbKeyA and not DoNotHandleA:
      'Do something
      bHandled =true
   case 191:
      if Shift = 1 then
         'Do something
         bHandled = true
      End if
   End select

if not bHandled then
  'Do default
end if
Avatar of sambha03

ASKER

I have something like the following already. Is it not possible to evaluate shift==1 in the case statement itself?
case 191:
     if Shift = 1 then
        'Do something
        bHandled = true
     End if
Regarding implementing
case vbkeyA
 if (DoNotHandleA=TRUE) then Proceed to default case

as
Case vbKeyA and not DoNotHandleA:

Thanks but its not exactly the solution i m looking for since I set DoNotHandleA to true/false after evaluating lots of conditions over many lines of code. Is it not possible to transfer out of the case statement to the next case statement after one case statement has already been evaluted to true?

Is it not possible to transfer out of the case statement to the next case statement after one case statement has already been evaluted to true?


No

Use

if not bHandled then
  'Do default
end if

I have something like the following already. Is it not possible to evaluate shift==1 in the case statement itself?

Try using the keyup event.


   Select Case KeyCode
      Case vbKeyR, vbKeySpace
          GoTo other
      Case vbKeyE
other:
        MsgBox "'E' pressed."
   End Select

I know. GoTo is foo paux.
ASKER CERTIFIED SOLUTION
Avatar of qwasted
qwasted

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Just noticed, that code will always say 'B' was pressed and ask if you meant to press 'N', it doesn't evaluate the case vbKeyB always because of it though.
It isn't transfering back into a select after a case has been found true, but i think it simulates what it is you are trying by stretching the cases over multiple select structures.