saving edit box inputs

  • Follow


Hi - I have written a program that allows users to save all the text
in edit boxes into a .mat file. However, I noticed that if I change
or enter an input in the edit box, then immediately choose 'Save
Settings' in the menu bar, the last change that I made does not save.
 It works if I click anywhere in the figure window (except the menu
bar), then select 'Save Settings'.

I looked over the 'Help' file in Matlab, and one thing it mentions
about edit boxes is "if an editable text box has focus, clicking on
the menu bar does not cause the editable text callback routine to
execute." I'm not using the edit box's callback routine, but I'm
wondering if this is somehow related to my problem. I don't know
what the Help file means though when it says "if an editable text box
has focus".

If anyone can provide any pointers, I'd really appreciate it! Thanks!
0
Reply sphchung (4) 1/27/2004 2:23:26 AM

The editable text box has focus if it is selected or being used - in
your case you are entering data into this box therefore it is in
focus. Clicking elsewhere on your gui takes this edit box out of
focus. As you said in your post, you can't save if the edit is
currently in focus.
Hope this helps a bit
Iain
0
Reply imurdoch (17) 1/27/2004 6:49:28 AM


Hi - thanks so much for your reply! I guess my next question is if
there is any way to set the edit box so that it's not in focus, like
a property? I looked through all the properties and didn't find
anything... I was wondering if there's something else I can set.
Thanks again for your help!

Steph

Iain wrote:
>
>
> The editable text box has focus if it is selected or being used -
> in
> your case you are entering data into this box therefore it is in
> focus. Clicking elsewhere on your gui takes this edit box out of
> focus. As you said in your post, you can't save if the edit is
> currently in focus.
> Hope this helps a bit
> Iain
0
Reply sphchung1 (1) 1/27/2004 7:01:27 PM

Stephanie Chung:

<SNIP wants to enter data in an edit box>

from a recent posting:

this is a slightly enhanced way of doing it - and it well may be an
overkill for your app.
for educational purposes, it employs two types of data containers.

1) save the code snippet below in a file, eg, <getdata.m>.
2) at the command prompt, type
     ic;
3) two controls are created:
     the top one is your edit box
4) enter any valid ML command that creates
   a number, eg,
          12/10
          sin(30*pi/180)
   the accumulated numbers will show up
   in the listbox below
5) if your finished, type two returns
   in your edit box
6) the accumulator will be cleared
7) retrieve your currend data set via
          d=getappdata(gcf,'data');
   in another program or the command window

%<<< CODE >>>
function getdata(uh)

if ~nargin
% create controls
     p.txt='enter data into edit box above';
     p.uh(1)=uicontrol('position',...
             [10 300 200 20]);
     set(p.uh(1),'style','edit');
     set(p.uh(1),'horizontalalignment',...
                 'left');
     set(p.uh(1),'callback',...
                 [mfilename '(gcbo);']);
     p.uh(2)=uicontrol('position',...
             [10 10 200 285]);
     set(p.uh(2),'style','listbox');
     set(p.uh(2),'max',1);
     set(p.uh(2),'string',p.txt);
     setappdata(p.uh(1),'handles',p);
else
% accumulate data until user enters
% two successive returns (== empty string)
     p=getappdata(uh,'handles');
     s=get(uh,'string');
     set(uh,'string',[]);
if ~isempty(s)
try
% evaluate input like sin(30*pi/180)
     s=eval(s);
     d=[get(p.uh(1),'userdata');s];
     set(p.uh(1),'userdata',d);
     set(p.uh(2),'string',d);
     set(p.uh(2),'value',length(d));
catch
% launch a warning
% here: do nothing
end
else
% store data in <gcf>
% clear accumulator
     d=get(p.uh(1),'userdata');
     setappdata(gcf,'data',d);
     set(p.uh(1),'userdata',[]);
     set(p.uh(2),'value',1);
     set(p.uh(2),'string',p.txt);
end
end
     return;
0
Reply us1 (8054) 1/27/2004 7:21:24 PM

3 Replies
34 Views

(page loaded in 0.036 seconds)


Reply: