Lyn - look closely at your if/elseif
if strcmp(eventdata.Key,'tab')
handles.a = handles.a + 1
elseif strcmp(eventdata.Modifier{:},'shift') && strcmp(eventdata.Key,'tab')
handles.a = handles.a - 1
end
For your elseif there are two conditions:
strcmp(eventdata.Modifier{:},'shift') && strcmp(eventdata.Key,'tab')
So the code will decrement a by one if both conditions are true. BUT, the second condition is the (only) condition for the if statement! So your elseif will never evaluate because the if will always take precedence.
Try the following instead
if strcmp(eventdata.Key,'tab')
if isempty(eventdata.Modifier)
handles.a = handles.a + 1
elseif strcmp(eventdata.Modifier{:},'shift')
handles.a = handles.a - 1
end
end
Try the above and see what happens! Note that you can remove the line
handles = guidata(hObject);
and just use the handles structure that is passed as the third input to this function.
Best Answer