Path: news.mathworks.com!not-for-mail
From: "Rodney Thomson" <readmore@iheartmatlab.blogspot.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: limit callback function?
Date: Fri, 18 Jul 2008 02:18:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 41
Message-ID: <g5ougp$hj3$1@fred.mathworks.com>
References: <g5orh5$kc7$1@fred.mathworks.com>
Reply-To: "Rodney Thomson" <readmore@iheartmatlab.blogspot.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1216347481 18019 172.30.248.38 (18 Jul 2008 02:18:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 18 Jul 2008 02:18:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1430350
Xref: news.mathworks.com comp.soft-sys.matlab:480162



"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