Controlling number of Characters typed into Edit Box using KeyPressFcn
Show older comments
I want to create an Edit box that only allow let say 5 characters and any extra characters should then switch to the next edit box.
function Name_Line_1_KeyReleaseFcn(hObject, eventdata, handles)
a=get(hObject,'String')
if length(a)> 5
uicontrol(handles.Name_Line_2)
end
However there was a big problem. When I run this without breakpoints, when I type 'Hello, World!' into the edit box, the curso won't jump to the next edit box. Only if I clink on the other uicontrols then back to the edit box, only the cursor jump to the next edit box.
I have placed a breakpoint at the line 'if length(a)>5' and ran it. If let say the Box already had 'Hell' in it, and now I type 'o', debug mode is activated but 'a' only contains 'Hell' not 'Hello'. If I tape the next letter 'w', 'a' will contain 'Hello' instead of 'Hellow'. However if now I give the command
a=get(hObject,'String')
in the command window 'a' contains 'Hellow' correctly. Why didn't it executes the command consistantly in the function as well as in the command window? What should I do?
Accepted Answer
More Answers (0)
Categories
Find more on Argument Definitions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!