Path: news.mathworks.com!not-for-mail
From: "ching l" <chinglnc@hotmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: limit callback function?
Date: Fri, 18 Jul 2008 14:36:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 61
Message-ID: <g5q9oh$bq6$1@fred.mathworks.com>
References: <g5orh5$kc7$1@fred.mathworks.com> <g5ougp$hj3$1@fred.mathworks.com>
Reply-To: "ching l" <chinglnc@hotmail.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1216391761 12102 172.30.248.35 (18 Jul 2008 14:36:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 18 Jul 2008 14:36:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1438759
Xref: news.mathworks.com comp.soft-sys.matlab:480280



"Rodney Thomson" <readmore@iheartmatlab.blogspot.com> wrote
in message <g5ougp$hj3$1@fred.mathworks.com>...
> "ching l" <chinglnc@hotmail.com> wrote in message
> <g5orh5$kc7$1@fred.mathworks.com>...
> > is it possible to limit the callback function?
> > 
> > for example, the gui button can only be pressed for 10
> > times, then the callback function is not valid anymore after
> > 10 times.
> > 
> > thanks.
> > 
> > 
> 
> You could just set up a field in the handles structure
> called count that is initialised to 1 in the OpeningFcn.
> Then the button callback becomes:
> 
> % --- Executes on button press in pushbutton1.
> function pushbutton1_Callback(hObject, eventdata, handles)
> % hObject    handle to pushbutton1 (see GCBO)
> % eventdata  reserved - to be defined in a future version of
> MATLAB
> % handles    structure with handles and user data (see
GUIDATA)
> 
>     handles = guidata(gcbo);
> 
>     if (handles.count <= 10)
>         fprintf(1, 'Pressed %d times\n', handles.count);
>         handles.count = handles.count + 1;
>     end
>     
>     guidata(gcbo, handles);
> 
> %-------------
> 
> Note, the callback is still valid and executed on each
> button press, just nothing really happens. However, you can
> allow the call back to function as before by resetting the
> value in handles.count to 1 by another callback.
> 
> --
> http://iheartmatlab.blogspot.com


I always have this kind of errors, and it happens again...
What can I do about it?

??? Reference to non-existent field 'count'.

Error in ==> listening>answer_faster_Callback at 110
if(handles.count<=3)

Error in ==> gui_mainfcn at 75
        feval(varargin{:});

Error in ==> listening at 42
    gui_mainfcn(gui_State, varargin{:});

??? Error while evaluating uicontrol Callback.